Thursday, September 3, 2009

Web Hosting Charges – How to cut cost by trimming your incoming data

Recently I worked on a project that involved putting a fairly complex hotmail preview widget on the ninemsn homepage. After completing development and integrated the widget on our homepage I realised that as the widget required the user to be signed in with their Live ID and we used RPS (Live ID for partner sites) we were getting very big client side cookies that were being used for profiling and authentication (total weight of these cookies were 800 Bytes).

When a user visits your site, their browser makes http calls for resources required to build the page (e.g. images, css files, javascript files). Now, each one of this http calls has a fixed header on it giving the server some details on each request. The problem is that all you local domain client side cookies also tag along with this header which increases the size of each http call.
As seen below using the Net tab.

If the browser makes 100 calls to the server requesting files, each one of these 100 calls will have the 800 Byte worth of cookie data as part of the header. So that’s 100 X 800 bytes worth of data being thrown to your server that hosts the files (most probably by your hosting company).

This is called ‘Inbound’ data and is usually free as part of the hosting plan (you usually pay for outbound data which is what hosting companies refer to when they say ‘data transfer limits’, this is basically the total files that are sent from the hosting companies servers to the users browser). Hoverer, if your hosting company does notice that your incoming data is generally high then are most likely to switch your payment plan to a plan that works on a ratio. For example, a 30:70 ratio which you pay for both incoming and outgoing data on a 30/70 split plan.

The plans can be a bit more complicated than this, but the bottom line is that you will end up paying for incoming data as well and this is where you need to shave off the extra cookies and extra calls made to your server.

Here are some tips:
1) Set up another domain and CNAME it to point to your main domain.

For example:
If you primary domain name is, buy another domain like www.just and create a CNAME that points to the primary domain So basically, going to www.just is the same as going to
Now, all your cookies that you use on your side for various reasons will most probably be set on your primary domain level. Write some server side code or just hard code all your resource calls to the primary domain to come from the secondary domain.

For example:
If there is a image called company_logo.gif on the page on your site instead of calling it like this company_logo.gif call it like this www.just company_logo.gif
Hope that makes sense. By doing this, when the request for the company_logo.gif comes to the hosting server it won’t carry any cookie info with it because the cookies have been set on the primary domain
Now you can actually call all the resources on your site (CSS files, Images, JavaScript files and even html/aspx pages) using the secondary domain and that massive cookie data which was been carried along on incoming server requests would now be completely removed. This should cut your incoming costs down dramatically.

2) Merge resources together
Instead of having 10 JavaScript files, put them into a single file. This was you make only 1 incoming call to the server and you actually speed up would site as well. You can do the same thing for CSS files as well.

I hope these tips help as it certainly helped my company save thousands, if you have any questions or comments please leave them below and I’ll get back o you guys.

No comments:

Post a Comment

Fork me on GitHub