Compressing A Website To Improve Its Speed

There are many ways to make your website loads faster, but in this blog post, I’ll mention the Zlib compression method for websites that are using PHP (i.e., scripting programming language).  According to what I’ve read so far on the Internet, Zlib not only can compress your PHP website to make it loads faster, it can also greatly reduce the amount of bandwidth that requires of your PHP/Apache server to serve the web requests to web browsers (i.e., website visitors’ browsers).  Of course, I’m not the one who had genuinely come up with this idea, and so I will produce the sources (i.e., on the information I write in this blog post) at the end of this blog post.

To have Zlib compression works for your PHP/Apache website, first you need to make sure that your PHP/Apache web server is actually has configured with Zlib module.  To do this, you can create a phpinfo test page to list the installed Apache and PHP modules.  An example of phpinfo test page can be found here.  To put this another way, you need to create a webpage ends with .php extension, and inside this webpage, you add an opening tag of php, a function of phpinfo (i.e., phpinfo();), and a closing tag of php to completely close the php program; don’t forget to save the php webpage so you can visit it through a browser to pull up the list of installed Apache and PHP modules.

Let say your php info test page confirms that your web server had configured with Zlib module.  Great!  All you have to do is to paste this tidbit of code which can be found here into your webpage, but make sure this very code goes above everything (i.e., above document types).  To put this in another way, you need to create an opening php tag, the php ob_start function (i.e., ob_start(‘ob_gzhandler’);), and to close up everything you add the closing php tag — this very code has to be above everything that resides inside your webpage.

There is another way to enable Zlib compression for your entire website by adding the right elements into your htaccess file.  Nonetheless, I’m still looking for the valid code for htaccess method.  The ob_start method (i.e., calling for ob_gzhandler function) is cumbersome for people who don’t use content management systems (e.g., WordPress, Drupal, etc…), because they have to add the php ob_start function (i.e., to call the ob_gzhandler function) to every webpage that they want to compress.  Luckily for WordPress users and other Content Management Systems’ users, because by adding the ob_start function to the headers of the websites’ templates (e.g., header.php, index.php, etc…) once — it suffices to say that such website owners have sufficiently enabling their websites to be compressed by Zlib.

To test to see if your website is actually compressed or not, you can visit here.  Another method is to download Google’s Page Speed extension for Chrome browser.  I believe Page Speed extension is also available for Firefox browser, but I’m not exactly sure on this.  You can find it out for yourself though!

Update:  Besides using Page Speed extension from your browsers (e.g., Chrome, Firefox), you can visit Page Speed Online to test out your website’s performance at pagespeed.googlelabs.com.

Update:  Also, you can try out webpagetest.org, because I find out this website has incorporated Page Speed into its test results for testing websites’ performances.

Sources:  http://www.desilva.biz/php/zlib.htmlhttp://php.net/manual/en/function.ob-gzhandler.phphttp://www.gidnetwork.com/tools/gzip-test.php.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.