Gzip Compression: How to Enable Gzip Compression in WordPress

Updated on

Gzip Compression reduces the size of HTML files, JavaScripts, CSS stylesheets and XML files. Generally, Enable(ing) Gzip Compression in WordPress with plugin reduces 60% to 80% size of your site. But I am saving 35,060 bytes using Gzip Compression in WordPress via .htaccess for technumero.com. And it is reducing webpage size by 82.2%. In this article, I will discuss what is Gzip Compression, how does it work, how to enable Gzip Compression in WordPress.

Gzip Compression can be enabled with or without using a WordPress plugin. You can easily enable Gzip Compression by adding the given below code in your .htaccess file. The .htaccess file can be found on your server (Apache) in the root directory of your domain.

Fastest WordPress Hosting Anywhere!

Enabling Gzip Compression in WordPress via .htaccess reduces Server Response Time and volume of data sent by the server to a web browser. Moreover, compressed page size help reducing the transferred response and data.

The best way to enable compression is, using mod_gzip or mod_deflate in WordPress .htaccess file. And the good news is, Gzip compression can be enabled by adding a simple code in WordPress .htaccess file (without plugin method) of your website.

Don’t worry if you don’t want to enable compression via .htaccess file.  I have also explained how to enable Gzip compression in WordPress using plugins like W3 Total Cache, WP Super Cache, and WP Fastest Cache, etc. In addition to that, I will show you how to enable DEFLATE compression.

Gzip Compression in WordPress
Gzip Compression in WordPress

Don’t be confused with the title – the Gzip and DEFLATE compression methods using .htaccess file and configuration file are server-dependent (i.e. Apache and Nginx). That means these methods work well with non-WordPress sites like HTML and other CMS based websites etc.

What is Gzip Compression?

Gzip is a file compressor that is used for compression and decompression of the files. It gives best results compressing text files (like stylesheets, HTML and JavaScript files).

When enabled on a website, Gzip compresses the files before transferring them from the server. Hence, it improves pagespeed, loading time and also saves data usage of the user. If you’re interested to know more about Gzip Compression check out these links [1, 2].

How does it work?

The concept of Gzip compression is quite easy.

It uses an algorithm which organizes repeated strings in a single place only, instead of saving those same strings again and again. And it manages those strings with their location values while compression and retrieving data back from compressed files.

Gzip compression works very well with stylesheets and webpages because all these resource files have many repeated strings.

Because of its efficient compression technique, Gzip may reduce the file size by 70-90%.

Let’s have a look at the given below example to understand the Gzip Compression…

Suppose if your HTML file contents following strings…

<h3>Enable Gzip Compression in WordPress </h3>

Then, the compressed file will look like this.

Hkg6dkGhJkjsdHkgHjL

But if your HTML file contents repetitive strings as following…

<h3>Enable Gzip Compression in WordPress</h3>

<h3>Enable Gzip Compression in WordPress via .htaccess</h3>

Then, Gzip compresses the repeated strings once and uses the latter part of your HTML file.

Hkg6dkGhJkjsdHkgHjL/GjDVjs

If you are working on pagespeed of your WordPress site then you should apply these too:

DEFLATE Compression vs Gzip Compression: The Difference

You might have read on the web about Gzip Compression and DEFLATE compression.

If you haven’t, let me tell you about them in nutshell. Both compression algorithms (Gzip and DEFLATE) are different and used for different servers.

Gzip compression is used on Apache and Nginx servers, while DEFLATE is only used on Apache servers.

Before you start, you must know Gzip compression status of your website. Let’s see, how to do that.

How to Check Gzip Compression

First, you should check whether Gzip Compression is enabled or not on your WordPress site. You can use this Gzip Test Tool for accurate results or you can Google Gzip compression test tool.

Check if GZIP Compression is enabled or not?
Check if GZIP Compression is enabled or not?

If compression is already applied to your site. Then you may check if compression is enabled properly. Or is there still scope for better compression? (the technique which reduces the files-size most is better one).

You also need to find out which web server software (Apache or Nginx) your web host is using. Because Gzip Compression method is different for both servers.

You also need to figure out, how to edit .htaccess/Config file. Here is a detailed guide How to edit WordPress .htaccess file easily you may refer.

Enabling Gzip & DEFLATE Compression in WordPress

You can enable Gzip compression in WordPress with or without using plugin.

  1. Enable Gzip Compression WordPress via .htaccess – without plugin method
  2. Enabling Gzip Compression in WordPress using plugin

Enable Gzip Compression in WordPress via .htaccess

As I have mentioned above, enabling Gzip Compression via htaccess/configuration file depends on the server i.e. Apache and Nginx, etc. So we’ll take both cases one by one. However, the process of editing the .htaccess (or configuration file in case of Nginx server) remains the same.

Step by step instructions to enable Gzip Compression in WordPress via .htaccess:

  1. Log in to Dashboard/cPanel of your website.
  2. Open .htaccess file (or config file in Nginx).
  3. Paste the corresponding code (given below) based on server type i.e. Apache or Nginx.
  4. Save changes and you’re done.
  5. Now check your site on compression testing tools again. It will definitely reduce your website page size significantly and will increase page-load speed.

Compression on Apache server

Apache server supports Gzip compression as well as DEFLATE compression.

Enable Gzip Compression on Apache server

If you’re your website is hosted on Apache server, add following code in .htaccess file of your website.

# BEGIN GZIP COMPRESSION
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP COMPRESSION

Enable DEFLATE Compression in WordPress

If you’re your website is hosted on Apache server, copy and paste the following code in WordPress .htaccess file of your website.

# BEGIN DEFLATE COMPRESSION
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/vnd.ms-fontobject" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
</IfModule>
# END DEFLATE COMPRESSION

Compression on Nginx server

Nginx server supports only Gzip compression. Let’s see to do that.

Enable Gzip Compression on Nginx server

If your website is hosted on Nginx server, paste the following code in the configuration file of your website.

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;

Results after Applying Compression

My blog TechNumero was hosted on Apache server, so I was using Gzip compression and DEFLATE compression both on my website. And it is reducing webpage size by 82.2%. Initially, my web page size is 42,656 Bytes (without compression) and after compression, my web page size is 7,596 Bytes only. Hence, I managed to save 35,060 Bytes using Gzip Compression on Technumero.com.

Gzip Compression in WordPress | Test Technumero.com
Gzip Compression in WordPress | Test Technumero.com

Enable Gzip Compression in WordPress using plugin

There are several plugins to the job at hand. Let’s discuss the most reliable and efficient ones.

Gzip Compression with WordPress Plugin – W3 Total Cache

W3 Total Cache is one of the most used caching plugins on WordPress platform. And if you are using this plugin, you can enable Gzip compression via this plugin.

Step by step instructions to enable Gzip compression using W3 Total Cache WordPress plugin:

  • Go to WordPress Dashboard > W3 Total Cache Plugin Settings page.
  • Navigate to Browser Cache page.
  • And Check the Enable HTTP Compression
  • Don’t forget to click on Save changes button and you are done.
Enable Gzip Compression using WordPress Plugin - W3 Total Cache
Enable Gzip Compression using WordPress Plugin – W3 Total Cache

Enable Gzip Compression with WordPress WP Super Cache Plugin

WP Super Cache is another popular caching plugin. And you can enable Gzip compression with just one click using this plugin.

Follow steps the given below to Enable Gzip compression with WP Super Cache plugin:

  • Navigate to WP Dashboard > WP Super Cache Plugin Settings
  • Click on the Advanced Tab and
  • Then Enable the First option in Miscellaneous settings.
  • Save the changes and you’re done.
Enable Gzip Compression with WordPress Plugin - WP Super Cache
Enable Gzip Compression with WordPress Plugin – WP Super Cache

Use WP Fastest Cache Plugin to Enable Gzip Compression in WP

WP Fastest Cache Plugin is another plugin which you can to enable Gzip compression in WordPress easily.

Followings are the easy steps to Enable Gzip compression using WP Fastest Cache plugin:

  • Go to WordPress Dashboard > WP Fastest Cache > Settings.
  • Under Settings Tab check the against Gzip to enable it.
  • Click Submit to save changes and you’re done.
Use WP Fastest Cache Plugin to Enable Gzip Compression
Use WP Fastest Cache Plugin to Enable Gzip Compression

Wrapping it Up

Gzip Compression is one of the most used technique for file compression. In addition to that, it is also one of the most recommended methods by pro bloggers for PageSpeed Optimization.

Nowadays, Gzip Compressions comes enabled by default with few modern web hosting servers. However, if it is not enabled on your server, now you know, how to enable Gzip Compression.

Feel free to fire your queries via the comment section below. Do let us know, how much file size you have reduced by enabling Gzip Compression?

General FAQ

What is Gzip Compression?

Gzip is a file compression software and a file format. Gzip compressor (software) is used for compression and decompression of the files in Gzip file format. Gzip compresses the files before transferring them from the server to improve to pagespeed, loading time of the website.

How do I enable Gzip Compression?

You can easily enable or disable Gzip Compression on your website by editing/adding a code snippet (given in the above technumero's article) to .htaccess or config file depending on your server type i.e. Apache, Nginx etc. All steps are explained to enable Gzip Compression on a website.

Is Gzip enabled on my website?

To check Gzip compression status of your website you need to test your site using a free Gzip test tool available online. Check out the Gzip test tool recommended by us (technumero.com) in above article for accuracy.

How do I enable Gzip Compression in WordPress?

You can enable Gzip Compression in WordPress with or without using a plugin. We use one of these two methods on our site and recommend it for better results. In above technumero's article, everything is explained step by step to enable Text Compression in WordPress.

In addition to that you may be interested to read the following tutorials:

Photo of author
Saurabh K
Saurabh K is a technology enthusiast and part-time blogger. He loves to explore the efficient use of technology and gadgets. He is an outlier and lensman. Add him in your social circle to know more.
Disclaimer: Affiliate links of some product(s) are being used on this page, if you follow the link and make a purchase, we may receive compensation from respective companies. This compensation comes at no additional cost to you.

33 thoughts on “Gzip Compression: How to Enable Gzip Compression in WordPress”

  1. Avatar of Harsha

    Hi,
    Gzip is enabled on the server side. I tried using the Gzip code you gave, and still Google
    PageSpeed Insights still suggests Enable compression and suggesting some CSS and JS files for this.

    Let me know the reasons and possibilities.

    Regards,
    Harsha

    Reply
    • Avatar of Saurabh K

      Hey Harsha!
      First of all thanks for leaving this response. One of the possible reason for your query may be “cache”. Next time before testing your website on Google PageSpeed Insights you should clear all type website cache. Hope this ‘ll help you out. Looking forward to listen more from you.

      Reply
  2. Avatar of Gab

    hi there,

    I’ve tried both mods, on my Apache server I have both Gzip and Deflate installed… Deflate slowed down browsing quite a bit, which I don’t understand why. Switched back to Gzip.

    results seem cached on Page speed insights, despite clearing the cache, he keeps saying “Enable compression” will try later. I used the test page you have at the top and passed.

    thanks for the useful post!
    Gabrio

    Reply
    • Avatar of Saurabh K

      Hey Gab!
      Glad that I could help. Clearing all caches should solve your issue. Looking forward to listen more from you. Thanks for awesome feedback.

      Reply
  3. Avatar of Gab

    Also GTmetrix still reports “Enable Gzip compression”.. what’s the catch?

    wordpress site with Super Cache installed.

    tnx

    Reply
  4. Avatar of Gab

    by the way, I noticed that Gidnetwork Gzip-Test and Whatsmyip Compression-Test both report I have compression enabled so my guess is that Google and Gtmetrix cannot detect Gzip when used via wordpress plugin that compresses the files.

    I can find on my server index.html.gz so that’s it 🙂

    cheers

    Reply
    • Avatar of Saurabh K

      Hi Gabrio,
      May be GTmatrix and Google are not detecting some plugins. You only need to make sure that Gzip is enabled.
      Glad you made it.

      Reply
  5. Avatar of Yasir Ghafoor

    its so nice Sharing, I am regular reader of your website, Its was so helpful for me thanks alot

    Reply
    • Avatar of Saurabh K

      Hey Yasir,
      Glad that I could help. Thanks for the fantastic feedback. 🙂

      Reply
  6. Avatar of Daniel Clark

    Thanks to sharing, this is really helpful for me.

    Reply
    • Avatar of Saurabh K

      Hey Daniel,
      Glad that i could help.
      Thanks for your response.

      Reply
  7. Avatar of Jagadeesh

    Thank you Saurabh K, Today your post helped me….

    i don’t have words to admire you, that’s way i say simply thank you very much. now on words am the fan of all your posts…

    Reply
    • Hey Jagadeesh,
      Glad that I could help you.
      Thanks for awesome feedback.

      Reply
  8. Avatar of Nasiha

    Hi
    my site is on Nginx server, and my compression is enabled, when I add Compression on Nginx server code to .htaccess file , then I have 500 respond, I even can check my website speed, shows 500 respond…

    any idea please!

    Reply
    • Hey Nasiha,
      If you able to long-in to WordPress, you can try to reload after removing the code. Else, you can long-in to your web-hosting account and can navigate to .htaccess file under your WordPress folder. From there you can edit .htaccess file and can remove the code. I hope this will help. Looking forward to listen more from you.
      Thanks for your response.

      Reply
  9. Avatar of Anubhav

    Hi Saurabh

    Great article . Motivated me to look for the better solutions ( not saying yours is not good i was using your solution).

    Reply
    • Hey Anubhav,
      Glad that you find it useful. Looking forward to listen more from you.
      Thanks for your response.

      Reply
  10. Avatar of Pramod Kumar

    Thanks brother, code is working nicely.

    Reply
    • Avatar of Saurabh K

      Hey Pramod,
      Glad that I could help.
      Thanks for dropping by.

      Reply
  11. Avatar of rishi

    How to add this code on Nginx server ?

    Reply
  12. Avatar of Gaurav Verma

    Your code working properly. When i check my blog speed in GT Metrix after add compression code. My site will faster up to 46 %. Thank Bro.

    Reply
  13. Avatar of Gaurav Verma

    With Your Guide, i enable Gzip compression without any error. I try many code but see an error. Thanks for providing a working code.

    Reply
    • Hey,
      Glad that I could help.
      Thanks for feedback.

      Reply
  14. Avatar of Vikas

    Hi Saurabh,

    i added both the code to my wordpress .htaccess file . And the tested GZIP enable or not here : http://checkgzipcompression.com/

    It still shows “GZIP is not enabled :(”

    Please help.

    Kind Regards,

    Vikas Panchal

    Reply
    • Hi Vikas,
      It should work, may i know the url on which you are trying to enable GZIP Compression.

      Reply
  15. Avatar of bilgi

    hi my web page speed increased. thanks

    Reply
  16. Avatar of cro in vancouver

    Apprecіate this post. Let mee try it οut.

    Reply
  17. Avatar of ALI

    Hi,
    We recently develop website for our company in Dubai UAE. the website size is more than 2.6 MB which is really slowing loading my site. I am abit confused here if you could please advise. do we need to use plugin or manual gzip compression method. which one is better please .

    Thnaks
    ALI

    Reply
  18. Avatar of Adel Sal

    Unfortunately, 99% of bloggers provide tips and recommendations for things that simply don’t work.
    You can see that they just don’t follow these tips themselves.
    You are my friend, is one of the rare 1% who is honest enough to recommend what he actually do and have with success.

    You page speed scores are 95% and 100% for mobile and desktop respectively which is quite impressive.

    One issue though, I noticed your website refreshes itself frequently while reading your posts which is annoying and may lead your readers to lose interest and subsequently bounce back.

    Thanks, Saurabh for these useful tips which helped me a lot with my website.

    Reply
    • Avatar of Saurabh K

      Hey Adel,
      Glad you find the recommendations helpful. And than you for your suggestion, will work on that.

      Reply
  19. Avatar of Chhatarpal

    Thanks to sharing, this is really needful for me

    Reply

Leave a Comment

Your email address and website details will not be published. Required fields are marked with *.