InfoPhilicWordPressBest Way to Enable Gzip Compression on your WordPress Site

Best Way to Enable Gzip Compression on your WordPress Site

What is Gzip Compression?

Gzip is a file format and software application used for file compression and decompression. Enabling Gzip Compression reduces file size by 60% to 80%, which helps the server for faster network transfers.

Enabling gzip on your server increases the page load speed of your website. Even I use Gzip compression on my websites.

How to enable Gzip compression

You can enable Gzip compression using the following methods:

  • Compression is enabled via the .htaccess file on your server
  • By Using W3 Total cache

Enable compression via .htaccess

To enable compression via the .htaccess file, put the following code in your .htaccess file on your server.

For Apache web servers with mod_gzip

The code below should be added to your .htaccess file

<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>

You can also compress using the DEFLATE mod. You must add the following code in the .htaccess file to do so. Don’t know how to edit the .htaccess file? Read about three correct ways to edit the .htaccess file.

For Apache web servers with mod_deflate:

# 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

You can use any one code of the above to enable compression on your server. Mod_gzip enables Gzip compression. Mod_deflate compress the output files from your server before it is being served to your visitor. Both have good compression results, so you can use any of them.

Enable compression on NGINX web servers

To enable compression in the NGINX web server, you will need to add the following code to the config 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;

# Disable for IE < 6 because there are some known problems

gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6

gzip_vary on;

If you are using a W3 total cache plugin, you don’t need to add any code stuff in your .htaccess file. All you need to follow these steps:

  1. Go to WordPress dashboard
  2. Open the Performance tab from the left navigation
  3. Under the Browser cache, check for Enable HTTP (gzip) compression

This will reduce the download time of the text-based files on your website.

Need help configuring the W3 Total cache plugin for the best results? Read:

Testing Gzip Compression

To check if the compression is working or not, visit https://tools.keycdn.com/brotli-test, input your website URL, and check the compression. That’s so easy 🙂

Testing Gzip Compression using Gzip compression testing tool
Testing Gzip Compression using Gzip compression testing tool

Conclusion

At the end of this tutorial, you must be learned to enable Gzip compression on your website. For Apache web server users, I would recommend using mod_deflate in the .htaccess file on the web server. This will also speed up your WordPress blog.

Also, test your WordPress blog speed using speed testing tools like Pingdom (an online service to check website speed). Not satisfied with your website speed? Read our tutorial, How to Make the WordPress Blog Faster.

You'll also like:
Continue to the category
Amit Malewar
Amit Malewarhttps://www.infophilic.com/
Amit Malewar has been the tutorial writer since 2013. His passion for helping people in all aspects of technology flow through the expert coverage he provides. In addition to writing for InfoPhilic, Amit loves to read and try new things.

Comment Policy: Your words are your own, so be nice and helpful if you can. Please, only use your real name and limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

GET STARTED
POPULAR NOW

Get almost 100% PageSpeed on Newspaper theme

The newspaper theme is the most popular premium theme for a self-hosted WordPress blog. The theme is developed by team tagDiv. You can buy this...
DEALS

WPEngine Hosting

GET 5 MONTHS FREE
spot_img