Enable Gzip compression in WordPress (and not only)

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


Published by Ivan Femia

I have more than 10 yrs of experience in IT; born as Windows Basis Administrator I moved rapidly to my real passion: web programming and R&D. I have been at Techedge since 2007 and I'm head of development of Techedge Labs Team. I focused my researches in emerging technologies, mobile, WebDynpro ABAP, Flash Island, Adobe Interactive Form and ABAP. My colleagues consider me one of the top reference for ABAP, ABAP OO, WebDynpro ABAP and high tech topic. I'm owner of the SCN Community Projects on SAP Code Exchange: abap2xlsx, augmentedSAP, abap2GApps, abap2docx and Clone Hunter. Follow me on Twitter @IvanFemia

Join the Conversation

2 Comments

  1. 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 comment

Leave a Reply

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

%d bloggers like this: