top_menu

Sunday, 29 July 2012

Compress webpage content using GZIP compression with PHP

.

The following piece of code will compress your website content. Ultimately speeding up your website to almost 20%.





Add the following code at the top of your PHP script which will compress the web page with GZIP compression.
 

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) 
ob_start("ob_gzhandler"); else ob_start(); 

?>

 
There are several ways to check and verify if the website is compressed with GZip or Deflate compression for its web pages and files.

Some of the popular online page compression test sites are: