Enable GZIP Compression
In this Article
How GZIP compression works
GZIP compression enables HTML, CSS and JS content to be compressed so that the files sent from the server to the visitor's browser are smaller. A smaller filesize means a faster download which improves the overall loading time of your page. We have an in-depth explanation on our blog.
NOTE: GZIP compression can only be applied to files served from your own domain NOT to those from 3rd parties - Facebook, Google, etc
How WP Rocket applies GZIP
On Apache servers, WP Rocket automatically adds GZIP compression rules in your .htaccess file using the mod_deflate module. These are the rules we add to your htaccess file:
Therefore there are 2 requirements for GZIP compression to work:
- mod_deflate has to be enabled on the server (ask your webhost),
- The necessary rules placed in your server configuration file.htaccess file, located in the root directory of your site.
Troubleshooting "enable compression" warnings
You may have used a tool like Pingdom, GT Metrix etc, to check the performance of your website and seen any of the following, or similar recommendations:
- "Compress components with GZIP" - Pingdom
- "enable text compression” - PageSpeed / Lighthouse
- "enable compression" - GT Metrix
- "compress components" - Yslow
- Pingdom does not provide the list of specific files that are being flagged, so if that’s what you used, re-run the test using either GT Metrix or PageSpeed.
- Then click on the message to expand it and view the list of files that are being flagged.
- Are the files listed hosted on your domain? If the files are external, i.e. not served from your own domain, you can't optimize them.
- Does your site use an htaccess file? As described above, WP Rocket adds GZIP rules in the htaccess file. Check with your host to see if:
You can read more about this in our doc:
Handling External Resources
If the files referenced are hosted on your domain, check the following:
- Your site uses an htaccess file. If it does, check the file to make sure the block of rules above are present
- Mod_deflate is enabled on the server
Some servers, have default maximum and minimum file sizes for compression. If the file is very large or very small it may not be compressed.
For example, very small files will not benefit from compression, and some file types should not be compressed. More info
If you are running your own server, here is some guidance about what you need in order to apply GZIP compression. Note we cannot provide support for modifications to your server config. We're providing this information as a helpful resource :)
If you run a dedicated Apache server you can activate mod_deflate by executing this command line:
…and restart the server afterwards:
service apache2 restart
Nginx doesn’t use an .htaccess. To enable GZIP on NGINX you can follow this guide:
Or you can use this alternate configuration for NGINX provided by one of our customers: