Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

前端 未结 23 1940
太阳男子
太阳男子 2020-11-21 07:19

What would be a good way to attempt to load the hosted jQuery at Google (or other Google hosted libs), but load my copy of jQuery if the Google attempt fails?

I\'m n

23条回答
  •  庸人自扰
    2020-11-21 08:00

    Using Razor syntax in ASP.NET, this code provides fallback support and works with a virtual root:

    @{var jQueryPath = Url.Content("~/Scripts/jquery-1.7.1.min.js");}
    
    

    Or make a helper (helper overview):

    @helper CdnScript(string script, string cdnPath, string test) {
        @Html.Raw("" +
            "")
    }
    

    and use it like this:

    @CdnScript("jquery-1.7.1.min.js", "ajax/jQuery", "window.jQuery")
    @CdnScript("jquery.validate.min.js", "ajax/jquery.validate/1.9", "jQuery.fn.validate")
    

提交回复
热议问题