The Geek House

Enable Gzip compression in WordPress (and not only)

by
2 Comments

Posted in General

Checking my blog performance I noticed that after the theme upgrade gzip compression is no longer active.

I will give you a easy tutorial in order to enable gzip compression without the installation of any plugins (like cache, super cache and so on) that I really hate.

First of all you need to check your php system gzip compression support.

Create a phpinfo.php file and upload to your site host (remember to delete it after the check)

<?php
phpinfo();
?>

From your browser launch the new phpinfo.php file http://www.yourblogurl.com/phpinfo.php and check php environment configuration

PHPInfo

If the gzip encoding is not enabled on your HTTP server check with your system admin how to enable it (on Apache HTTP Server refers to mod_deflate).

Open your index.php and add the following lines on the top

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


Save and upload the new index.php and it’s done.

Now check your site compression for example using this tool http://www.whatsmyip.org/http_compression/, you will see something like this

GZip


2 Responses

  1. Pingback: Tweets that mention Enable Gzip compression in Wordpress (and not only) | Plinky Blog -- Topsy.com

  2. suze says:

    thank you so much, I’ve tried and used different gzip plugins and it caused my blog to not work or open even, and the feed wasn’t updating.

    I did what you said and it worked just fine. thank you so much, and have the best day. :)

Leave a Reply

%d bloggers like this: