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.
CSS/JS/HTML are pre-compressed
When WP Rocket creates the cache file for each page, it creates 2 versions - an HTML file and a GZIP file. The GZIP-ed version will usually be served, but the HTML is there as a fallback.
When File Optimizations are applied, such as Minify/Combine CSS and JS, WP Rocket also creates 2 versions of each file, but they are not served automatically.
Please see this guide for more information about this feature.
Your server must have the gzencode function available in PHP.
Troubleshooting "enable compression" warnings
- "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
NOTE: In some rare cases, GZIP compression might not be applied only to HTML documents, even, if mod_deflate is enabled and .htaccess rules are present. You should then add the following directive to your user.ini or php.ini file placed in the WordPress root:
zlib.output_compression = On
Don't forget to check your site afterwards!
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: