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

前端 未结 23 1475
太阳男子
太阳男子 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条回答
  •  梦毁少年i
    2020-11-21 08:03

    For those people using ASP.NET MVC 5, add this code in your BundleConfig.cs to enable the CDN for jquery:

    bundles.UseCdn = true;
    Bundle jqueryBundle = new ScriptBundle("~/bundles/jquery", "//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js").Include("~/Scripts/jquery-{version}.js");
    jqueryBundle.CdnFallbackExpression = "window.jQuery";
    bundles.Add(jqueryBundle);
    

提交回复
热议问题