Fallback for jQuery UI from google CDN

后端 未结 3 1464
我寻月下人不归
我寻月下人不归 2020-12-31 06:54

Html5 Boilerplate uses the following trick for fallback to locally stored JQuery if grabbing it from Google CDN fails:



        
3条回答
  •  孤城傲影
    2020-12-31 07:09

    Using the ASP.NET Web Optimization Framework

    Easier way to do it when you're using bundles.

    Get the Microsoft.AspNet.Web.Optimization package from NuGet. Now in your BundleConfig you can setup your bundles to include not only the CdnPath, but also a CdnFallbackExpression:

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.UseCdn = true;
        BundleTable.EnableOptimizations = true;     
        var jquery = new ScriptBundle("~/bundles/jquery", "//ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js").Include(
                "~/Scripts/jquery-{version}.js");
        jquery.CdnFallbackExpression = "window.jQuery";
        bundles.Add(jquery);
        //...
    }
    

提交回复
热议问题