Enable GZIP compression

This article contains information about the GZIP compression, its definition, how WP Rocket applies it, troubleshooting and guidance for server administrators.

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/LiteSpeed 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: 

# Gzip compression
<IfModule mod_deflate.c>
# Active compression
SetOutputFilter DEFLATE
# Force deflate for mangled headers
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
# Don’t compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf|mp?g|mp4|webm|webp|pdf)$ no-gzip dont-vary
# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
		                          application/javascript \
		                          application/json \
		                          application/rss+xml \
		                          application/vnd.ms-fontobject \
		                          application/x-font-ttf \
		                          application/xhtml+xml \
		                          application/xml \
		                          font/opentype \
		                          image/svg+xml \
		                          image/x-icon \
		                          text/css \
		                          text/html \
		                          text/plain \
		                          text/x-component \
<IfModule mod_headers.c>
Header append Vary: Accept-Encoding
<IfModule mod_mime.c>
AddType text/html .html_gzip
AddEncoding gzip .html_gzip
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.html_gzip$ no-gzip

Therefore there are 2 requirements for GZIP compression to work:

  1. mod_deflate  has to be enabled on the server (ask your webhost), 
  2. 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
  1. 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.
  2. Then click on the message to expand it and view the list of files that are being flagged.

  3. Are the files listed hosted on your domain?
  4. If the files are external, i.e. not served from your own domain, you can't optimize them.

    You can read more about this in our doc: 
    Handling External Resources

    If the files referenced are hosted on your domain, check the following: 

  5. Does your site use an htaccess file? 
  6. As described above, WP Rocket adds GZIP  rules in the htaccess file.  Check with your host to see if:
    • 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
  7. What is the file size?
    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.
  8. Not all components should be compressed
    For example, very small files will not benefit from compression, and some file types should not be compressed. More info

HTML not GZIP-ed

In some specific server configurations, all the static assets will be correctly compressed, but you may receive a warning specifically about the HTML document not being compressed. 

There are 2 possibilities to resolve this: 

1. Make sure the cache is served by our htaccess rewrite rules

  • Disable Separate cache files for mobile devices  (This is not required on most sites that have responsive themes) 
  • Disable User Cache

2. If the above configuration is not possible (sometimes our htaccess rewrites are removed for compatibility), try enabling zlib compression on your server:

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!

Server admins

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/LiteSpeed server you can activate mod_deflate by executing this command line:

a2enmod deflate

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:

IIS - Windows

IIS servers don't use an htaccess file. GZIP has to be enabled on the server configuration level. You can follow this guide to enable GZIP on IIS servers:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.