Welcome to WebmasterWorld Guest from

Forum Moderators: phranque

Message Too Old, No Replies

Two ways to save bandwidth



2:54 am on Apr 2, 2006 (gmt 0)

Inactive Member
Account Expired


One of the issues that I am facing on my website and I am sure most webmasters will have to face at some point whith their websites, is monthly bandwidth. Bandwidth is expensive and and can be used up pretty quickly, forcing many of us to additional payments towards our webhosting companies.
Besides the bandwidth problem, there is also the problem of download speed. Especially on new generation websites, which are more "heavy" than older generation websites, a single page can easily be over 100 kb. Big deal you might think, but consider 2 facts. That your website has many pages (well most do!) and that there is a signifact number of users out there who are not on broadband connections and they are using Dialup or low bandwidth connections to the internet. On a 56 kbits dialup connection, with an average of 5kbyte download ratio at best, a 100 kb page would take about 20 seconds to load. Well that is a long time to wait! even on a broadband connection of lets say 256 kbits (25 kbyte average) it might take for the page 4 seconds to load.

There is a solution that can satisfy both the webmaster, that wants to speed up his website and cut down bandwidth usage by us much as 60% or more and the website users, that want fast loading websites with a lot of content. The magic word is Compression!
For compression to work, both the server and the client need to understand it and support it. There has been in our web browsers for years! support for compressed web pages, and as for the servers, there are a number of tools out there that can enable them to server compressed content to users.

The most widely used compression tool on webservers is mod_gzip for apache (there are also solutions available for Microsoft IIS servers, but I will talk about them on other guides if you wish, as they are commercial tools)

Mod_gzip is a module for apache (existing on both windows and unix/linux versions of apache) that can significantly lower the size of a webpage on the fly, when it is requested by a browser that can understand compressed content (almost all modern browsers do support compression). Remember, the great thing is that the compression on the server is activated only if the browsers requests compressed content, in case the browser does not understand compressed content or does not request for it, the server simply servers plain, uncompressed content!

Most people claim that setting up compression on the apache is a pain, but i think it is very easy and for webmasters, which have a basic level of knowledge about apache, it will be an easy task. I can write a guide if there is such request from the users on how to setup apache on unix/windows with mod_gzip enabled.
Also, besides mod_gzip there is also mod_deflate, which is similar to gzip but some people claim that it has even better compression ratios.

For those of you out there which do not have your own webservers, mod_gzip is most of the time supported by your provider servers. Just ask them to enable it. It is only logical that most providers do not enable it by default, as it will save you bandwidth (and loose them money since they charge you for that extra bandwidth). In case that your hosting provider does not enable mod_gzip for some reason, do not despair.

There is another magic word that can save your day!
The word is: PHP
Believe it or not, a single line of PHP on the header of a webpage can compress the whole page (just like mod_gzip would).
So, in order for the PHP compression to work, you should insert the following line on the header of your webpages, on the top that is of your page :

<? ob_start("ob_gzhandler");?>

Thats it! with that simple line, the html content of your webpage will be compressed on the fly! And the good news is that PHP is enabled on most of the provider servers out there (well if you have a joomla/mambo server that it definately is!)

Regarding CPU usage and the speed of compression, it is not something that you have to worry about if you use mod_gzip, mod_deflate or the php function above. In all cases, the CPU usage is minimal to zero, and the response time of your server will be even better than before. An 100 kbyte webpage, when compressed can go to almost 20 k or less, depending on the content, as the text has always very high compression ratios.

For real life examples, the 100 kbyte page that would take 20 seconds to load on a dialup user browser and 100 kbyte of your bandwidth, with compression would drop down to 20 kbyte of bandwidth and 4 seconds of loading time for the user! As for the broadband user? the page will load in 1 second! Pretty good for FREE dont you think?

Thats it for now! If you think that is guide was helpful, i might be able to write down a more detailed guide on how to implement and how to test compression functionality on your web servers.

[edited by: txbakers at 3:23 am (utc) on April 2, 2006]
[edit reason] no signatures or personal URLs [/edit]

4:48 am on Apr 5, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 5, 2006
votes: 0

Some others:
1) whenever possible avoid downloading images, instead find an HTML/CSS solution.
2) PHP can also be used to cut all breaklines out of your output.
3) don't use any HTML comments.
4) if a divider or span will do the same job, then avoid using tables.
5) cut large pages into smaller indexed pages, especially if you can group the page's content by relevancy so if a person really doesn't care about the less relevant portions they don't have to download them.