- Files are downloaded from the best geographical location
- CDN networks are trusted and built for high availability and high usage
- The browser can download files from several servers at the same time.
- CDN networks can use caching to further improve performance
Here is an example of what can be done for the ~/bundles/query that is set by default on a new project.
// use CDN if it is available.
// NOTE: Won't show on local machine unless turn debugging off in web.config
bundles.UseCdn = true;
var bundle = new ScriptBundle("~/bundles/jquery",
bundle.CdnFallbackExpression = "window.jquery";
Be sure to set the bundles.UseCdn = true. Also, if you are running your project under debug (set in the web.config) then you won't get the bunding, minimizing, optimizations, etc, but you would in production. To force these in development, set debugging to false in the web.config.
Here is a list of CdnFallbackExpression values for common CDNs.
## Library ## ## Expression ## jQuery window.jQuery jQuery.UI window.jQuery.ui Modernizr window.Modernizr Bootstrap $.fn.modal jquery.transit $.transit jquery.validate $.validator json2 JSON.stringify webfont WebFont jquery.blockUI $.unblockUI() respond window.respond moment window.moment
NOTE: List copied from here and the augmented.
Great post on CDN