How to Enable WordPress GZIP Compression
You actually need to enable WordPress GZIP compression on the server-side rather than the WordPress side. When you buy hosting from popular hosting companies, you’ll find that in their standard hosting packages they’ve already got this enabled. With some other web-hosting providers, you’ll need to do this yourself.
If you discover that WordPress GZIP compression isn’t enabled yet, you can use one of a few different methods to begin. We are going to go through a few ways of enabling GZIP compression in WordPress that should suit you whether you’re a beginner or a highly experienced web developer.
Enable WordPress GZIP Compression under Apache
You can switch on GZIP compression for your WordPress website by making changes to your .htaccess file ( which is part of Apache infrastructure ). A lot of people take this approach, but unfortunately doing it this way means that there is a chance that something might get broken! It’s hardly surprising because messing with a sensitive server file like .htaccess means that one little mistake can have big consequences that crash your website.
To lower your chances of messing up your WordPress website, do the sensible thing and backup your original file before you change anything, not only that but backup your WordPress website too! Once you’re completely sure that you can recover from a catastrophic failure if you need to, it’s time to get things underway.
The .htaccess file is usually hidden on both the remote server as well as your computer, you should be able to find it in your website’s root folder.
The ideal method is to access the file using FTP, and we could also use another admin interface or Plesk.
To enable WordPress GZIP compression in your FTP client, you’ll need to make hidden files visible.
Once you find your .htaccess file, you can make changes, but first it might be better to download it to your own computer and make them there. The file is most likely going to be hidden on your machine so you need to instruct it to show hidden files.
Compress JavaScript, Text, HTML, CSS, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
Save the file, using it to overwrite your original .htaccess file. Check your website with a GZIP compression checker tool (or verify the response headers) to check if it worked.