Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telerik().ScriptRegistrar() How to prevent loading jquery libraries?

Script registrar loads jquery.validation.min.js even after

Html.Telerik().ScriptRegistrar().jQuery(false)

Is there any way to tell it not to do so?

Even when I try to load exactly what I need, doing this:

@Html.Telerik().ScriptRegistrar().jQuery(false).DefaultGroup(g =>
{
    g.Add("telerik.common.min.js");
    g.Add("telerik.tabstrip.min.js");
}

And if for example I have a telerik grid on the page it would load all necessary scripts including grid.min, grid.editing and jquery.validate.min.

I prefer to control it myself and instead of that simply to get an error, or non-functioning elements if I forgot to define the right scripts.

If I try to use this snippet:

@Html.Telerik().ScriptRegistrar().jQuery(false).Scripts(s =>
{
    s.Add("telerik.common.min.js");
...

It ignores useTelerikContentDeliveryNetwork="true" in web.config, and searches for scripts on local server. I still want to use CDN.

UPD: Is there actually a way to use telerik's CDN sources but if for some reason they are down, load all the stuff from the project's server?

like image 794
iLemming Avatar asked May 26 '11 15:05

iLemming


2 Answers

As a further update to this answer for people coming from search engines: You can now remove jQuery Validation in addtion to jQuery by using something like:

@Html.Telerik().ScriptRegistrar().jQuery(false).jQueryValidation(false)
like image 70
Heretic Monkey Avatar answered Nov 18 '22 11:11

Heretic Monkey


.jQuery(false) indeed prevents including of jquery.js only. It does not affect jquery.validate.js and was never meant to. Currently there is no way to stop the ScriptRegistrar from including jquery.validate.js when there is an editable grid in the page.

There is no built-in support for fallback when you are using the Telerik CDN. A manual workaround can be implemented though. Something like this:

@(Html.Telerik().ScriptRegistrar())
<script type="text/javascript">
    if (typeof jQuery === "undefined" || typeof $.telerik === "undefined") {
       // the CDN failed for some reason use local files
       document.write("<script src='scripts/telerik.common.min.js'><\/script>");
       document.write("<script src='scripts/telerik.grid.min.js'><\/script>");
       // etc
    }
</script>
like image 4
Atanas Korchev Avatar answered Nov 18 '22 10:11

Atanas Korchev