Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle Multiple CSS Served From a CDN?

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?

like image 685
Ken Burkhardt Avatar asked Nov 14 '12 15:11

Ken Burkhardt


People also ask

How do I bundle CSS files?

The following example shows how to combine multiple CSS files into a bundle. public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles. Add(new StyleBundle("~/bundles/css"). Include( "~/Content/bootstrap.

What is CSS CDN?

A content delivery network (CDN) refers to a geographically distributed group of servers which work together to provide fast delivery of Internet content. A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, javascript files, stylesheets, images, and videos.

What is bundling in CSS?

Bundling is the process of rolling up a number of distinct resources together into a single downloadable resource. For example, a bundle may consist of multiple JavaScript or CSS files you bring down to the local machine by making a single HTTP request to an ad hoc endpoint.


1 Answers

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

like image 185
Markus-ipse Avatar answered Sep 26 '22 18:09

Markus-ipse