Top 3 Methods to Enable Gzip Compression in WordPress

Why Should We Enable Gzip Compression?

There are several benefits to enable Gzip compression because it’s the most popular method to load your site faster by reducing more than 70% page size of your blog. However, now-a-days most of the sites are using Gzip compression across the web. Gzip will load your site in just a few seconds.

Benefits

  1. Search more likely prefer you in search results
  2. Your server will no longer get large server requests to process
  3. 1000 KB page size will converted into 100KB

Enable Gzip Compression

Time to time there have been developed several resources to enable Gzip for WordPress sites. There are 3 methods to enable Gzip compression in WordPress following are these:

1. Enable Gzip using Existing (Maybe not) WordPress plugin W3 Total Cache

The most popular plugin (W3 Total Cache) which have a great role in improving your WordPress site performance, it also let you Gzip your site (To enable Gzip compression using w3 total cache, go to Performance > Browser Cache).

Enable Gzip via W3 Total Cache

2. Enable Gzip Compression via .htaccess

Gzipping an easy way to reduce weight per page of your site. You can enable Gzip compression by adding the following code to your .htaccess file:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png

Don’t know how to edit .htaccess file directly from WordPress dashboard, click here.

3. WP HTTP Compression Plugin

This plugin allows you to output the pages in Gzip compressed format. HTTP compression generally means a 60-80% reduction in the size of your pages. Follow these steps to enable Gzip for WordPress:

1. Download, install and activate WP HTTP Compression

2. There is no settings page by this plugin because it works automatically, further see if your site is working after the installment of this plugin here = IS MY SITE WORKING.

TaDan! It’s Done!

How People found this article:

79 Responses

  1. Aksam Zarook February 13, 2013 / 6:53 am

    I’d never heard about this method of making site’s faster. Thanks for this useful post.

  2. Ashok Jaria April 4, 2013 / 10:16 am

    Hi
    Where should I add the following code to my .htaccess file (place) is there any specific place?

    • Muhammad Haroon April 4, 2013 / 10:27 am

      Hi thanks for the comment and letting me know about the issue. Let me tell you that there is not any specific way but you can add the line of codes just after the #END WordPress in your .htaccess file.

      • Drew Hammond April 18, 2013 / 6:59 am

        You should never add custom code in between the #BEGIN WordPress and #END WordPress lines.

        WordPress automatically generates this section and any time you make modifications to something like Permalink settings, everything you’ve added between these lines will be overwritten.

      • Xeshan Ali September 29, 2013 / 3:45 pm

        I have been added it before End now my website is completely spoiled and not working shown 500 internal error even my wp directory also not working. please help me

        • Muhammad Haroon September 29, 2013 / 3:47 pm

          Hi Xeshan Ali, let me know if you are using any caching plugin or minify plugin for CSS or JavaScript files.

  3. nferoozi April 18, 2013 / 10:43 pm

    Thanks Haroon,

    Your post was really helpful.

  4. tomastry June 6, 2013 / 7:56 pm

    very helpfull post Haroon. Thanks for sharing.

  5. Steph M June 10, 2013 / 8:48 pm

    So I have enabled gzip with your code in the htaccess. I tested it with this tester and it worked.

    However, PageSpeed is still telling me to enable it and telling me which files should be compressed. So do I need to compress the files for this to work? How do I do this? And if I compress the files can I not edit them in WordPress as usual? For example, it wants me to compress main.css

    Thank you!

    • Muhammad Haroon June 10, 2013 / 10:16 pm

      If you have just enabled the Gzip compression then why the pagespeed testing tool is asking you to enable compression on main.css? I’m using the same method to gzip my entire blog. In this case use wp-minify plugin to minify the CSS files only.

  6. Alan June 11, 2013 / 2:27 am

    Thanks for the tip. I was getting a slow page speed at the Google Page Speed checker. After following your instructions I went from a 62 to an 87.

    • Muhammad Haroon June 11, 2013 / 6:12 am

      Your welcome @Alan. Thanks for sharing your views toward my article.

  7. vinay June 27, 2013 / 10:57 am

    Thanks Muhammad, Thats what i was looking for ….

  8. Hemant Aggarwal July 7, 2013 / 6:48 pm

    Thanks for the tip but do you know how to add expire headers in WordPress?

  9. malum July 27, 2013 / 5:34 pm

    Thanks for the tutorial. i add the code to htaccess and my page speed increase to 86%. Thanks

  10. Harga Jual PABX August 1, 2013 / 12:10 pm

    thanks bro,
    i will try to my project website, i hope this tutorial working done.

  11. VHamilton August 1, 2013 / 7:54 pm

    Thanks for this code. would rather use code than plugins when I can.

    • Muhammad Haroon August 1, 2013 / 7:56 pm

      Yeah! That would rather more better than using a plugin…

  12. Amine August 6, 2013 / 4:44 pm

    Enable Gzip Compression via .htaccess Like it !
    Thx

    • Muhammad Haroon August 6, 2013 / 6:03 pm

      Yeah! Hope that worked like a charm in your WordPress blog, @Amine… Your welcome by the way.

  13. Salvatore Capolupo August 9, 2013 / 12:54 pm

    Hello, I don’t know why but when I active ZIP compression using htaccess I can’t see any page on the blog (I’m exploiting Super WP Cache too), but I just download a zip file without seeing anything. Any idea about this ? Thanks for you post :)

    • Muhammad Haroon August 9, 2013 / 7:08 pm

      Your welcome, If you are using WP Super Cache make sure that it’s setup correctly in your WordPress blog.

      By the way, on adding the gzip codes in your .htaccess file the pages of your blog goes off as you said. Solution for this problem is that, you are using the multiple times compression options once the WP super cache compression option and the other one is by .htaccess file. You should use one time, rather than multiple, if you use multiple time compression option then they will conflict each other and the result would be the blank pages.

      Regards,
      Muhammad Haroon

      • Salvatore Capolupo August 10, 2013 / 3:19 pm

        Hello, you got the idea, it seems that WP Super Cache was also compressing my website files: so you should just choose, using htaccess manually or check plugin option for compression (and they say as notice, there is no WARRANCY that all will be ok).

        • Muhammad Haroon August 10, 2013 / 3:31 pm

          Well, you got it right brother. You should only use the manual method and uncheck the option from WP Super Cache. It’s that easy solution for your problem.

          Muhammad Haroon

  14. cosmina August 15, 2013 / 8:19 pm

    worked great! Thanks a lot for the useful information! :)

  15. Felipe Brandão August 24, 2013 / 1:55 am

    Great post! I was already using the option “Compress pages so they’re served more quickly to visitors. (Recommended)” of wp-super cache checked. This option enables also enables gzip, but my grade was really bad on yslow and PageSpeed told me to make the gzip compression.

    When I used your second method Google PageSpeed told me: You have compression enabled. And Yslow gave me a C Grade. 72% and 92% on GTmetrix.

    Is there any problem using WP Super Cache method plus .htaccess from ur post?

    Cya

    • Muhammad Haroon August 24, 2013 / 7:56 am

      Hey @Felipe Brandão,

      Thank you for admiring my article, and by the way I’ve already told you guys about this problem here. Hope you doing well.

  16. Herman Rosa August 27, 2013 / 1:42 am

    Nice, thnx! using step 2 my site jumped up 15 points on Google’s speed insight test.

    • Muhammad Haroon August 27, 2013 / 12:04 pm

      Well @Herman Rosa, I know that. And many of people using this method as you did. By the way, your welcome and hope you doing well these days.

  17. Rizwan September 16, 2013 / 4:34 pm

    Awesome Info about gzip compression. i will apply this thing on my blog.

  18. Jeroen October 6, 2013 / 3:38 pm

    “2. Enable Gzip Compression via .htaccess

    Gzipping an easy way to reduce weight per page of your site. You can enable Gzip compression by adding the following code to your .htaccess file:”

    That simple, huh? When the host doesn’t allow mod_deflate, nothing will happen, right?

    • Muhammad Haroon October 6, 2013 / 4:43 pm

      HI @Jeroen,

      Yes, you are right. But still you can use the third way of enabling gzip compress:

      3. WP HTTP Compression Plugin

      This plugin allows you to output the pages in Gzip compressed format. HTTP compression generally means a 60-80% reduction in the size of your pages. Follow these steps to enable Gzip for WordPress:

      1. Download, install and activate WP HTTP Compression

      2. There is no settings page by this plugin because it works automatically, further see if your site is working after the installment of this plugin here = IS MY SITE WORKING.

      TaDan! It’s Done!

      • Jeroen October 6, 2013 / 7:45 pm

        Thanks Muhammad, I’m going give this a try since I have been spending hours on getting the gzip working via htaccess and W3 Total Cache (and other plugins)

        • Muhammad Haroon October 6, 2013 / 8:54 pm

          Your welcome @Jeroen, keep visiting my blog. Sure you can give it try and by the way best of LUCK.

  19. Sohil Memon October 30, 2013 / 1:15 am

    Thanks for the plugin Sir. But can I use this simple plugin? wordpress.org/plugins/wordpress-gzip-compression

    Do check it out and please tell me! Thanks in advance.

    • Muhammad Haroon October 30, 2013 / 11:25 am

      Hi @Sohil Memon,

      Thanks for the commment, and by the way manual process would be fine enough… Through .htaccess file, rather than using the third method of gzip compression… Okay. Hope you understand.

  20. Jared Del Re November 6, 2013 / 6:36 am

    I added the code and my website speed did not increase at all? Am i doing something wrong? My speed from google is 52/100 its really hurting business

    • Muhammad Haroon November 6, 2013 / 11:21 am

      Well @Jared Del Re,

      Let me know if you are using any caching plugin already on your blog? If so, please remove that plugin first.

      • Jared November 6, 2013 / 7:15 pm

        The only one I had active was wp-optimize and its now removed, with no difference

  21. July,es November 7, 2013 / 9:17 am

    Hi Haroon, Thanks for sharing. It was really useful.

  22. David November 14, 2013 / 5:29 am

    Thank you SO much for the Gzip compression code for the .htaccess file. I was running a 21/100 and 25/100 for mobile/desktop page load tests via PageSpeedTest insights on Google Developers. I’m now at 55/100 and 68/100 respectively. Your Gzip code fixed the majority of my slow response time. Now my host just needs to get their act together and get my server running more smoothly. Thanks so much.

  23. Riy December 22, 2013 / 10:30 am

    Hello,

    This is the article I have been looking for. Thanks for the information.

    I added the code in my .htaccess. However, there is no difference in the speed test or google page speed test. What could be the problem, I really prefer the htaccess option

    Do you think I should try to install WordPress plugin W3 Total Cache or the WP HTTP Compression Plugin? Do you have any preference

  24. Riy December 22, 2013 / 12:33 pm

    Hello

    Thanks for the post.

    I added the code that you provided to my .htaccess through ftp edit.
    But, no change in the page speed.
    Any suggestions

    • Muhammad Haroon December 22, 2013 / 1:18 pm

      Hi @Riy, let me know if you are using any caching plugin…

      Suggestion: Use only one either caching plugin or use the .htaccess codes…

  25. Riy December 22, 2013 / 5:48 pm

    hI
    thanks for the reply
    i am not using any caching plugin

    • Muhammad Haroon December 22, 2013 / 6:43 pm

      Okay, in this case you use the 3rd method i.e, WP HTTP Compression Plugin. And remove the codes from .htaccess hope you this will work for your blog.

      • Riy December 23, 2013 / 1:25 am

        Hi,

        I installed the w3 total cash and performance improved. Option 1. Thanks for that.

        My question now is I want some pages not to be cached and I want to add it in the Never cache the following pages section

        what is the format /my-account/* or my-account/* or the faq says something like /my-account/.+

        appreciate your help

  26. gujjufreak January 7, 2014 / 12:25 am

    I use Total Cache plugin and hence i just need to sit back and relax.

  27. Cara Linda February 4, 2014 / 1:05 am

    I do not want to use too many plugins, so I think I will enable GZip compression via htaccess

  28. William February 7, 2014 / 7:10 pm

    Thanks a lot, I put the code in my .htaccess file, and now my site is in 66% in Page Speed Insights, before it was 40%

    • Muhammad Haroon February 7, 2014 / 8:57 pm

      Wow, that awesome William. Happy good Pagespeed day ;)

  29. James Rutter February 14, 2014 / 3:53 pm

    Hey Muhammad, thanks a lot for your great post. I was just wondering: would you recommend doing all three of these methods at once – or should you only do one at a time? And if you should, which one method would you recommend the most?

    • Muhammad Haroon February 14, 2014 / 4:18 pm

      Your welcome @James on my blog, but I recommend you to use one method at a time rather doing all at once. And by the way, the method that I would recommend you the one using .htaccess file. Hope you understand. Keep visiting my blog thanks.

  30. Aamer March 1, 2014 / 5:45 pm

    Hello Haroon,

    I have used .htaccess method for gzip compression on my blog. Thanks for sharing.

  31. Abhinav singh March 23, 2014 / 12:51 am

    thanks for sharing. this method had help me to improve my website a lot.

  32. Graphic Ashen April 3, 2014 / 1:13 pm

    Thanks, I used the second method to counter some non-compressed fonts on my server.

    Went up by 4% page speed!

    Thanks again.

  33. harlemtal June 13, 2014 / 1:58 am

    I used the Yoast SEO method you suggested. I got an increase of 13 points. It was simple, easy and worked. Yeah, you the man bro…

  34. Rahul July 16, 2014 / 10:57 am

    it really helped me lot.. Thanks for the post

  35. savan July 25, 2014 / 12:18 pm

    Before this tips my site speed 10 second and now my site speed is 3sec :) Thanks for the post

Leave a Reply

Your email address will not be published. Required fields are marked *


− 4 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>