How To Enable Gzip Compression In WordPress Via .htaccess File

Smaller file sizes help you to achieve faster loading time on your WordPress Site. The size of your webpage can be reduced by using Gzip compression.

Gzip Compression reduces the size of HTML files, JavaScripts, CSS stylesheets and XML files.

Also, google alerts for sites that do not have compression enabled. In this guide, you will learn how to enable Gzip compression to your WordPress website by modifying the .htaccess file.

Prerequisites

  • A Domain name (example.com)
  • cPanel Credentials
  • FTP Client (Cyberduck, Filezilla)
  • Text Editor (Notepad, Sublime Text)

How does Gzip Compression Work?

The working of Gzip compression is very simple. 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 fine with stylesheets and web pages because all these resource files have many repeated strings. Because of its compression technique, Gzip can reduce the file size by 80-90%.

Step 1:

Login into your cPanel with your username and password.

How To Enable Gzip Compression In WordPress Via .htaccess File

Step 2:

Click on File Manager under the Files section.

Step 3:

Locate the .htaccess file located in the public_html directory. You can also use the Filezilla client application to locate the .htaccess file.How To Enable Gzip Compression In WordPress Via .htaccess File

How To Enable Gzip Compression In WordPress Via .htaccess File

Step 4:

Right click the .htaccess file and Click on Edit. It will show up the Edit pop up. Click on Edit button.

How To Enable Gzip Compression In WordPress Via .htaccess File

Step 5:

Add the following line of codes at the end of your .htaccess document

# BEGIN GZIP COMPRESSION
<IfModulemod_gzip.c>
mod_gzip_onYes
mod_gzip_dechunkYes
mod_gzip_item_includefile.(html?|txt|css|js|php|pl)$
mod_gzip_item_includehandler^cgi-script$
mod_gzip_item_includemime^text/.*
mod_gzip_item_includemime^application/x-javascript.*
mod_gzip_item_excludemime^image/.*
mod_gzip_item_excluderspheader^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP COMPRESSION

Add the following line of codes if your website is hosted on a Nginx server.

gzipon;
gzip_comp_level2;
gzip_http_version1.0;
gzip_proxied any;
gzip_min_length1100;
gzip_buffers168k;
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_varyon;

Step 6:

Click on Save Changes to save your changes.

Step 7:

There are WordPress plugins available which can help to enable to Gzip compression to your site. W3 Total Cache is one of the most used popular caching plugins on WordPress. Using this plugin, you can enable Gzip compression.

You can enable Gzip compression with W3 Total cache by going to its settings page. Go to the Browser cache page. Enable the HTTP compression option and click on Save Changes.

Conclusion

Congratulations, You’ve learned how to enable Gzip compression in your WordPress website using the .htaccess file. You can also enable compression using different caching plugins like W3 Total cache or GZip Ninja Speed Compression. Nowadays, Gzip Compressions comes enabled by default with modern web hosting servers.

Check out these top 3 WordPress hosting services:

Was this article helpful?