CDN module without a content delivery network

Modern web browsers put a cap on the number of connections they make to a host. This means if you've got a lot of assets on one hostname the browser will queue the remaining assets, while the ones in front download. This is referred to as blocking.

One way around blocking is to create multiple subdomains, for instance, assets0.davidstoline.com and assets1.davidstoline.com to increase the number of resources downloaded in parallel. This is method is called domain sharding and it is recommended by both Google's PageSpeed and Yahoo's YSlow.

I can't exactly afford a high quality CDN like Akamai but I can still leverage some of the benefits and fun of using a CDN. My friend Wim Leers wrote the Drupal CDN module, which you can leverage to do a little home grown sharding of your own.

In my nginx configuration for davidstoline.com I added...

  server_name assets0.davidstoline.com;
  server_name assets1.davidstoline.com;

Then in my Drupal sites directory I created two new directories for assets0.davidstoline.com and assets1.davidstoline.com with a settings file that looks like

<?php
die();
?>

I set it up to die(); because I don't actually want to serve my site from those two subdomains.

Boom! Now you just configure the CDN module to use those two subdomains. Just download, install and enable Wim's CDN module. Visit admin/config/development/cdn/details and add something like

http://assets0.davidstoline.com|.css
http://assets1.davidstoline.com

And you're set. You may want to tweak your CDN module setup if you serve a lot of image assets.

Tags: