MVC Using a CDN Bundling and Minification
MVC 4 CDN Enable using BundleCollection
The follow code replaces the local jQuery bundle with a CDN jQuery bundle.public static void RegisterBundles(BundleCollection bundles) { //bundles.Add(new ScriptBundle("~/bundles/jquery").Include( // "~/Scripts/jquery-{version}.js")); bundles.UseCdn = true; //enable CDN support //add link to jquery on the CDN var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"; bundles.Add(new ScriptBundle("~/bundles/jquery", jqueryCdnPath).Include( "~/Scripts/jquery-{version}.js")); BundleTable.EnableOptimizations = true; }In the code above, jQuery will be requested from the CDN while in release mode and the debug version of jQuery will be fetched locally in debug mode. When using a CDN, you should have a fallback mechanism in case the CDN request fails.
MVC Using a CDN Bundling and Minification
Reviewed by Bhaumik Patel
on
8:06 PM
Rating: