13 Mar

Use CDN Bundle Config in ASP.NET MVC

In this post we will learn how to use  CDN bundle config  in ASP.NET MVC.

CDN will use the distributed network when enabled, and in optimization mode.

You cannot combine multiple CDN’s together (one script only).

By default. UseCdn is set to false.

Implementation

Enable UseCdn feature

 bundles.UseCdn = true;

Next add the jQuery Bundle from the CDN

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

CdnFallbackExpression is used when even CDN server is unavailable.

CDN bundle config

bundles.UseCdn = true;
            var jqueryBundle = new ScriptBundle("~/bundles/jquery", "http://code.jquery.com/jquery-2.0.3.min.js").Include(
                "~/Scripts/jquery-{version}.js");
            jqueryBundle.CdnFallbackExpression = "window.jquery";
            bundles.Add(jqueryBundle);

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>