Compressing Web Pages with GZIP
Print this Article
Comment on this Article
Last Updated:
May 13, 2008 2:20 PM
Compression is a simple, effective way to save bandwidth and speed up your Web site in Linux Shared Hosting. By adding a piece of PHP code to the top of your Web pages, you can instruct the Web server to compress files for transit to your visitors' Web browser. This is especially useful for text-heavy Web pages that are over 100K in size.
To Optimize Your Site With GZIP Compression
Add the following code to the very top of your Web pages above the DOCTYPE:
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
Rename the file you want to compress with a .php extension instead of .html or .htm and upload the file to your site. The file will be compressed upon request and delivered to the visitors' browser.