Reputation: 10386
I know the advantages of CDN and I also understand what benefits MVC4 Bundling and Minification offer.
I want to know that is it possible to combine the benefits of MVC4 Bundling and Minification and CDN. What I mean is that can we publish the bundled and minified script or css to a CDN and then in views we access the minified version through CDN url?
Upvotes: 4
Views: 1166
Reputation: 553
You can combine MVC4 Bundling and Minification with CDN
http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification
Code from the page above:
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.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
// Code removed for clarity.
}
Upvotes: 0
Reputation: 1764
Yes it is perfectly possibly and a good practice to publish the Minified script to your CDN. I routinely see both on various CDN's. This allows the developer to choose which version they need.
...then in views we access the minified version through CDN url?
Yes, you will access the minified version with the CDN url.
Upvotes: 2