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

可紊 提交于 2019-12-10 13:25:37

问题


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?


回答1:


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)



回答2:


.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>


来源:https://stackoverflow.com/questions/6141001/telerik-scriptregistrar-how-to-prevent-loading-jquery-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!