3 Ways to setup CDN like service for your blog for free

A CDN or a Content Delivery Network is a system which can enhance the performance of a web-site by delivering its static content from different geographic locations, typically locations closest to the client’s location. Commercial CDN services from Akamai et al. are pretty expensive for amateur bloggers/web-site owners. Amazon S3 can also provide CDN like functionality for hosting static files but misses some key functionality of a CDN like gzip content-encoding and cache-control. We are going to discuss three ways in which we can have a CDN like service for a web-site/blog.

  1. Using Google Code Hosting Service: Google provides free code hosting service for OpenSource projects through Google Code. We can use this to deliver our content by following these steps:
    1. Sign-up for a Google Account and go to http://code.google.com/hosting/createProject to create a new project. We name it “techtatva” in our case and fill in the other details. We chose Mercurial as our version control system, you can also choose SVN. Since all the static content on our website is already available to the public it is OK to keep it OpenSource. ¬†Just keep in mind that you do not put any dynamic content, script or passwords in the repository.
    2. Now lets clone the repository
      1. hg clone https://techtatva.googlecode.com/hg/ techtatva
    3. Next, we put all our static contents in this directory. In this case, we put the TechTatva header image as a test file.
    4. Now lets push the files on to the repository
      1. hg add .
      2. hg commit -m "Putting some static content"
      3. hg push

      When asked for username, use the Google Account email id associated with the appengine id. The  password for the project can be found at https://code.google.com/hosting/settings
    5. If the push was successful we are done. We can get our static file at http://techtatva.googlecode.com/hg/logo-red.png or http://<your-project>.googlecode.com/hg/<your-static-content.file>. Now, these URLs can be used for serving the static content on the website.
  2. Using Google AppEngine (Static Files method): Another simple way in which we can setup our own content delivery is by using Google AppEngine. This can be done by following these steps:
    1. Create a new Google AppEngine application at http://appengine.google.com/
    2. Download the SDK and set it up.
    3. Create a new application with the following code in the `app.yaml` file
      1. application: techtatva-test # should be <your-app-id>
      2. version: 1
      3. runtime: python
      4. api_version: 1
      6. default_expiration: '365d'
      8. handlers:
      9. - url: /
      10.   static_dir: static

      Replace “techtatva-test” with your AppID. Check out http://code.google.com/appengine/docs/python/config/appconfig.html for more information.
    4. We then put all our static contents in the `static` directory
    5. Run the following command to commit the changes to Google AppEngine
      1. appcfg.py update .
    6. All Done! We can now get our static file at http://techtatva-test.appspot.com/logo-red.png or http://<your-app-id>.appspot.com/<your-static-file.name>
  3. Using a Google AppEngine Based Object Caching Technique: This technique is a bit advanced but is very useful. It saves a lot of time consumed in maintaining multiple static file repositories. In this case we keep all our static files on our standard webserver and use Google AppEngine as a Caching proxy to deliver our content. Here the copies of the static files are stored as binary objects in the AppEngine Datastore and AppEngine Memcached, which then get delivered to the clients’ browser. For this there is a very useful OpenSource AppEngine based software known as CirruxCache. It can be configured by following these steps:
    1. Download and extract the latest stable version:
      1. wget -c http://cirruxcache.googlecode.com/files/cirruxcache-0.3.1.zip
      2. unzip cirruxcache-0.3.1.zip
    2. Create your own Google AppEngine account and use the appengine id in the `app.yaml` of CirruxCache
    3. Open `app.py` file in your favorite editor and replace the lines 50~59 with the following:
      1. urls['default'] = (
      2. 		'(/debug/.*)', 'Debug',
      3. 		'/_admin/(.*)', 'Admin',
      4. 		'/_store/(.*)', 'Store',
      5. 		'/(.*)', 'Www',
      6. 		'/_cron/(.*)', 'Cron',
      7. 		)
    4. Now go to line number 66 of `app.py` i.e. class Www and assign your source domain name to the variable origin
    5. Commit the changes to AppEngine by running
      1. appcfg.py update .
    6. Now we can access static files at http://www.your-domain.com/static-file.static from http://<your-app-id>.appspot.com/static-file.static without actually uploading it to AppEngine. We can also use custom domains on Google AppEngine (http://code.google.com/appengine/docs/domain.html)

Note: Google AppEngine has limits to their free account, check out http://code.google.com/appengine/docs/quotas.html. If you are using the above techniques on a high volume blog do not forget to enable billing on your AppEngine account.

Awaiting your comments!

This entry was posted in Tips and Tricks and tagged , , , . Bookmark the permalink.

2 Responses to 3 Ways to setup CDN like service for your blog for free

  1. Pingback: Tweets that mention 3 Ways to setup CDN like service for your blog for free | TechTatva -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *