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.
Enable GZIP Compression on NGINX
Although the majority of most shared hosting plans use Apache web servers, you could be using something else, like NGINX.
To enable GZIP compression for NGINX web servers you have to go about it differently. If you’re running on NGINX, you can enable GZIP compression in WordPress by finding your nginx.conf file and adding this code:
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;
Contact Your Web Host to Enable GZIP Compression
If you’re not comfortable making changes to your website files, it’ll be easier to ask your web host to enable WordPress GZIP compression for you.
A lot of web hosts, including GoDaddy, Kinsta, and Siteground enable WordPress GZIP compression automatically because it improves performance so much, while others will give you the instructions and let you set up WordPress GZIP compression yourself.
If you don’t have GZIP compression enabled by default and you’re not sure how to change that, then don’t be afraid to talk to your web host. Most of them will usually be perfectly happy to help you.
A Plugin to Enable WordPress GZIP Compression
WordPress GZIP Compression can be set up using a plug-in, but while that may be easier it could also expose you to additional security issues and take up more disk space on your server. But if you do choose to go down this route then here are some plug-ins that can help you enable WordPress GZIP compression.
Lots of the tools that let you enable GZIP compression on your WordPress site are caching suites which are there to help you set up your website for best performance. Compressing HTML, JavaScript and CSS files is certain to improve it.
But Enable GZIP Compression was designed for only one purpose, enabling and disabling GZIP compression for your WordPress site when it’s on an Apache webserver.
WP ROCKET
WP Rocket is a caching plugin, and in just a few clicks it can help WordPress sites load faster. Once you’ve activated it, WP Rocket adds GZIP compression rules in the .htaccess file using the mod_deflate module.
W3 TOTAL CACHE
W3 Total Cache is among the best WordPress caching plugins, but it isn’t for beginners and it may break your website if you don’t know how to use it correctly. But if you are comfortable then it can be useful for helping you to enable HTTP compression. Just go to the browser cache, and then check the box for HTTP compression.
WP SUPER CACHE
WP Super Cache is another WordPress cache plugin that lets you compress code.
To enable WordPress GZIP compression with WP Super Cache, go to the WordPress dashboard > WP Super Cache > Advanced > and check the box for Compress pages. This will ensure that they’re served to visitors more quickly.