How To Enable Gzip Compression In WordPress Via .htaccess File

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:

A2 Hosting
£2.40 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
Hostinger
£2.40 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
HostArmada
£2.00 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How To Backup Your WordPress Site To Google Drive

In this guide, we will learn to back up our wordpress site easily to Google Driv
1 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Configure WordPress Page Caching

A savvy website owner understand how important it is to have a website with a qu
4 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Secure Your WordPress Website

Millions of websites get hacked every year and many people consider WordPres
5 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How To Create a WordPress Child Theme

Customizing your WordPress theme but want to be extremely safe? Don’t worry. W
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top