 |
 |
 |
 |
 |
 |
 |
 | mod_gzip - Speed Up Your Page Load Time | Sunday, 19 October 2008 @ 09:47 PM |
|
 |
 |
| |
One of the biggest turnoffs for visiting a website is slow page loading times. You may have the best looking site on the planet but if your site takes eons to load, no ones going to bother. At least I won't. Here's one solution to speeding up your website using gzip compression in PHP. This is especially useful for sites with lots of content/text.
Adding this line of code just before the opening <html> tags.
Quote: if(isset($_SERVER['HTTP_ACCEPT_ENCODING'])){
if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && extension_loaded('zlib')) {
ob_start(array('ob_gzhandler',5));
ob_implicit_flush(0);
if (ereg("MSIE", $_SERVER['HTTP_USER_AGENT'])) {header('Content-Encoding: gzip');}
}
else{
ob_start();
ob_implicit_flush(0); // perform a flush operation, pushes content directly to user every output call
}
}
else{
ob_start();
ob_implicit_flush(0); // perform a flush operation, pushes content directly to user every output call
}
To test if your page uses gzip compression, visit this link:
http://whatsmyip.org/mod_gzip_test/ |
|
 |
 |
 |
 |
| |
 |