Using CDN in MVC script bundle. What am I missing?

Solution 1:

Run your application in debug="false" mode or use BundleTable.EnableOptimizations = true;

Solution 2:

Actually you can write @RaviGadag his method shorter when using a recent version of ASP.NET MVC. This way you don't have to write the fallback yourself in the Layout:

public static void RegisterBundles(BundleCollection bundles)
{

  bundles.UseCdn = true;

  var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.3.min.js";
  var jqueryBundle = new ScriptBundle("~/bundles/jquery", jqueryCdnPath).Include("~/Scripts/jquery-{version}.min.js");
  jqueryBundle.CdnFallbackExpression = "window.jQuery";
  bundles.Add(jqueryBundle);

  // ...

  BundleTable.EnableOptimizations = true;
}

available jquery versions in the Content Delivery Network (CDN): http://www.asp.net/ajax/cdn#jQuery_Releases_on_the_CDN_0