Drupal 7 CDN
This article was automatically recovered from archived versions of this site via the Wayback Machine. It is likely outdated or contains formatting errors, as it has not been reviewed.

Drupal 7 CDN

January 27, 2013
drupalhtaccessCDN

I was playing around with CDN, a module for Drupal which provides everything necessary to run your own “poorman’s content delivery network”. However, in my case it’s not really a network of servers, just a simple and cheap way to circumvent some of the HTTP protocols limits of only allowing 2 concurrent connections per host.

I’m not going into all the details here .. google it, there’s plenty of text already written about that. Granted, new browsers don’t really care much about that anymore and upped the limits, but still, if you end up with a lot of HTTP request per pageload, it still makes sense to see whether grabbing your content from multiple hosts makes a difference in terms of pageloading times.

In my case it did. I splitted up delivery of different static file types like .js, .css, .png, .jpg and so on to 4 different hosts. Using the network traffic analyzer provided by every browser’s developer tools, you can verify how much of an improvement that alone makes. Not on this page tho: doesn’t have enough traffic to care about something like that.. :-) The page I tested it on has an average of 20 to 30 HTTP requests per pageload, due to the fact that it serves a lot of images and uses a lot of jQuery and friends.

Drupal isn’t really known to be the holy grail of optimization. You can end up easily with 6-9 js bundles and the same amount of css bundles per page. In addition, there’s 4-5 webfonts, a couple of images and sprites .. well, even a browser with a limit of 6 concurrent connections will have to fetch all of the files in more than 4-5 separate attempts.

The total amount of blocking time by images and the fact that almost all CSS files can be fetched in one or two attempts makes the sites render faster and therefore improves the overall UX. And I’m all for that. :-)

Now if you run a site on a regular hosting environment, you will create subdomains and map them to a single directory. This directory will proxy to the root of the main domain, which requires mod_proxy, and will only allow static files to be served. You don’t want your website to be available on 5 different domains, The Goog doesn’t like that, so we don’t allow it.

Here’s the .htaccess I used to accomplish said feature: