2

I'm using jquery.curvycorners and typeface in a website and I want to have those scripts loaded in the head of the page (in order to have the page rendered correctly from start).

Now I'm introducing some Telerik components and the ScriptRegistrar is giving me a headache.

It seems it doesn't want to render at two places even if it's two separate groups.

Abbreviated example:

    <% Html.Telerik().ScriptRegistrar().Scripts(s => s
           .AddGroup("Group1", group => group

               // jQuery    
               .Add("jquery-1.4.4.min.js")
               .Add("jquery-ui-1.8.9.custom.min.js")

               // Rounded corners
               .Add("jquery.curvycorners.source.js")

               .Combined(false)
               .Compress(false)
           ))
           .Render();
    %>

</head>
<body id="body">

    <div>

yadda yadda...

    </div>

    <% Html.Telerik().ScriptRegistrar()
            .DefaultGroup(group => group
                .Compress(false)
                .Combined(false))
            .jQuery(false)
            .Render(); %>
</body>
</html>

Should I hand pick those components I really need to load from start and use script tags or are there any way of using the scriptregistrar rendering in two places?

2 Answers 2

3

You shouldn't be loading the ScriptRegistrar in two places. Also, the script registrar should always be at the bottom of the page. If you absolutely need to have javascript references before the ScriptRegistrar you could do the following:

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
    @Html.Telerik().StyleSheetRegistrar().DefaultGroup(g => g.Add("telerik.common.css").Add("telerik.windows7.css"))
</head>

<body>
    <div class="page">
        ...
    </div>
    @Html.Telerik().ScriptRegistrar().jQuery(false);
</body>
</html>

Otherwise I recommend combining the two at the bottom, disabling the built-in jQuery and add your own in a group like you did above.

Sign up to request clarification or add additional context in comments.

2 Comments

That's what I was afraid of... I really need those scripts on the top of the page. And it would have been nice to have them combined and compressed.
For some reason, I don't always get the scripts at the botton of the page using ScriptRegistrar() and then my treeview doesn't work... :( I wonder what could cause this... So far, I link the telerik JS at the head too. :( I use output caching to some of my controller actions that produce treeviews, perhaps that's it. :(
0

You can only call Render() once on a page. Try removing the first one.

1 Comment

Exactly, but it's a pity because waiting with loading some scripts makes the page give the impression of loading slower.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.