We are looking into the new bundling feature of ASP.NET MVC 4 and are wondering if there are any advantages to bundling CSS files that are served from a CDN?
Is there even a way to bundle multiple files served up from a CDN in ASP.NET MVC 4? This doesn't work:
var cdnCssPath = "http://MyCdn/css/";
bundles.Add(new StyleBundle("~/Content/css", cdnCssPath)
.Include("~/Content/site.css")
.Include("~/Content/Test1.css")
.Include("~/Content/Test2.css")
.Include("~/Content/Test3.css")
);
Any ideas?
First of all it depends on if you have access to a CDN where you can upload your own files or if you're using, for example, google's CDN to get external libraries like jQuery.
If you pull files from a CDN and bundle them, you would lose the advantage of using a CDN unless you're able to upload your new bundled file to the CDN.
For example if you get jQuery and jQuery UI from google's CDN and bundle them, you're no longer using google's CDN, you're instead serving up local resources (the created bundle). You may have reduced the number of requests, but instead of 2 requests too google's CDN (which has a high probabillity to be cached already by the users browser) there's one request to your server (which is not as likely to be cached).
So in short I would say that there's no advantage to bundle files together that comes from a CDN, however uploading your bundled files to a CDN is different story.
Do note that it is possible to use use CDN for bundles though: look at the "Using a CDN" part of this article
Edit: Here's an article that explains when to use a CDN or not and why, a bit more indepth than my answer http://www.kendoui.com/blogs/teamblog/posts/13-11-07/know-when-to-cdn.aspx