There are many Content Distribution Networks (CDN) aka Content Delivery Networks out there so why create your own? I for one argue that most CDNs out there don’t host enough code.
Here’s a list that google supports:
Yahoo! User Interface Library (YUI)
This may seem as a long list, but what if you use jQuery plugins like jQuery validate or Fancybox often?
Why not create your own CDN system to host the code you use the most (You can even choose to use googleapis for all the libraries that are available and use your own CDN for the ones that are not). Personally, I prefer that option.
Another benefit of hosting your own CDN is that if you create web applications using a in-house made CMS you can also host its icon-sets and other frequently accessed static images.
The reason’s to use a CDN are simple and straight-forward:
Using a CDN will save you bandwich
Using a CDN will greatly increase your scripts load speed
So how do you create your own CDN?
#1 Setup the domain
#2 Figure out a filetree structure
Your filetree is very important when setting up your CDN. Yes, you can simply put every file you need in the root directory of the webserver but this is clumbersome and after some time will become confusing.
Google uses the following syntax:
You can also use this syntax or use a more simplified version. Which I personally prefer since the code you should host on your CDN often does not come with that many versions.
I then use the library folder to host specific libraries (and their specific plugins), the plugins folder to host plugins (such as modernizr) and the image folder to host my frequently used images.
#3 Making it perform
As said before, you should disable cookies on the domain of your choice.
Because you are using a CDN you can use a custom .htaccess file to optimise the content distrubution. Set far-future (the content is static anyway) expire headers and deflate any content delivered.
#4 All done
It’s that simple to create a very basic CDN. Obviously there are other more advanced topics we could discuss about how to optimize the distribution of content, but this is in essence a CDN that does what it promises.