Fix Guide

How to Enable Gzip or Brotli Compression in WordPress

February 8, 2026

When a browser requests a page from your WordPress site, the server sends back HTML, CSS, JavaScript, and other text-based files. Without compression, these files are transmitted at their full size. Enabling compression can reduce these file sizes by 70-90%, which directly translates to faster page loads and lower bandwidth costs.

How Compression Works Behind the Scenes

Compression relies on a negotiation between the browser and the server. When the browser sends a request, it includes an Accept-Encoding header that lists the compression algorithms it supports, typically gzip, deflate, br. The server checks this header, compresses the response using the best available algorithm, and sends it back with a Content-Encoding header indicating which method was used. The browser then decompresses the content before rendering it. This entire process is transparent to the end user.

There are two main compression algorithms you will encounter:

  • Gzip: The industry standard for over two decades. Supported by every browser and web server. Compression ratios of 70-80% are typical for text-based files.
  • Brotli: Developed by Google and released in 2015. Offers 15-25% better compression ratios than Gzip for similar CPU usage. Supported by all modern browsers. Only works over HTTPS connections.

Which File Types Should Be Compressed

Compression works best on text-based, repetitive content. You should enable it for the following MIME types:

  • Text files: text/html, text/css, text/javascript, text/xml, text/plain
  • Application files: application/javascript, application/json, application/xml, application/rss+xml, application/atom+xml
  • Fonts and SVGs: image/svg+xml, font/ttf, font/otf (WOFF and WOFF2 fonts are already compressed)

Do not compress binary files like JPEG, PNG, WebP, GIF, MP4, or PDF. These formats already use their own compression algorithms, and re-compressing them wastes CPU without reducing file size.

Expected Size Savings

To give you a concrete idea of what compression achieves, here are some real-world examples:

  • A typical WordPress HTML page (80 KB): Compresses to roughly 15-20 KB with Gzip, or 12-16 KB with Brotli.
  • jQuery library (90 KB minified): Compresses to about 30 KB with Gzip, or 25 KB with Brotli.
  • Bootstrap CSS (160 KB): Compresses to around 25 KB with Gzip, or 20 KB with Brotli.
  • A large JSON API response (500 KB): Compresses to roughly 50-80 KB with Gzip.

Across an entire WordPress site, enabling compression typically reduces total transfer size by 60-80%.

Apache: Enable Gzip with mod_deflate

If your WordPress site runs on Apache (which is the case for most shared hosting providers), add the following to your .htaccess file. Place it before the WordPress rewrite rules:

<IfModule mod_deflate.c>
    # Compress HTML, CSS, JavaScript, Text, XML and fonts
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/woff

    # Remove browser bugs for older browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Make sure proxies deliver the correct content
    Header append Vary Accept-Encoding
</IfModule>

The IfModule wrapper ensures this configuration is only applied if mod_deflate is installed. On most hosting providers, it is enabled by default. If you get a 500 Internal Server Error after adding this code, contact your host to confirm that mod_deflate is available.

Nginx: Enable Gzip Compression

If your server runs Nginx, add the following directives to your server block or the http block in your nginx.conf file:

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/json
    application/javascript
    application/x-javascript
    application/xml
    application/xml+rss
    application/atom+xml
    image/svg+xml
    font/ttf
    font/otf;

A few notes on these settings: gzip_comp_level 6 offers a good balance between compression ratio and CPU usage. Levels above 6 provide diminishing returns while significantly increasing CPU load. The gzip_min_length 256 directive prevents compression of very small files where the overhead of compression outweighs the savings. The gzip_vary on directive tells caching proxies to store separate versions for compressed and uncompressed content.

Nginx: Enable Brotli Compression

Brotli is not included in the standard Nginx package. You need to install the ngx_brotli module separately, or use a distribution that includes it (many modern Linux distributions offer it as an optional package). Once installed, add this to your Nginx config:

brotli on;
brotli_comp_level 6;
brotli_min_length 256;
brotli_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/json
    application/javascript
    application/x-javascript
    application/xml
    application/xml+rss
    application/atom+xml
    image/svg+xml
    font/ttf
    font/otf;

You can run both Gzip and Brotli at the same time. Nginx will serve Brotli to browsers that support it and fall back to Gzip for the rest. This is the recommended setup for maximum compatibility.

WordPress Plugins That Handle Compression

If you do not have access to server configuration files (common on shared hosting), several WordPress caching plugins can enable compression for you:

  • WP Rocket: Automatically adds Gzip compression rules to your .htaccess file upon activation. No additional configuration needed. This is a premium plugin.
  • LiteSpeed Cache: If your host uses the LiteSpeed web server, this plugin enables compression at the server level, which is more efficient than Apache's mod_deflate. Free and available on the WordPress plugin directory.
  • W3 Total Cache: Offers Gzip compression as part of its Browser Cache settings. Enable it under Performance > Browser Cache > HTTP compression. Free, but has a steeper learning curve.
  • WP Super Cache: Includes a "Compress pages" option that serves pre-compressed static files. Simpler than W3 Total Cache but with fewer options.

Keep in mind that if your hosting provider already enables compression at the server level, adding it again through a plugin will have no additional effect. Check first before making changes.

How to Test Whether Compression Is Working

After enabling compression, you should verify it is actually being applied. Here are several methods:

  • Browser DevTools: Open your site, press F12 to open DevTools, go to the Network tab, and reload the page. Click on any HTML, CSS, or JS request and look at the response headers. You should see Content-Encoding: gzip or Content-Encoding: br. You can also compare the "Size" column (compressed transfer size) with the "Content" or "Resource" column (actual decompressed size).
  • Online tools: Websites like GTmetrix, Google PageSpeed Insights, and KeyCDN's compression checker can verify that your site serves compressed content. They will flag uncompressed resources if any are found.
  • Command line: If you have access to a terminal, you can use curl -H "Accept-Encoding: gzip" -I https://yoursite.com to see the response headers. Look for the Content-Encoding header in the output.
  • InspectWP scan: Run a new InspectWP scan after enabling compression. The performance section will display the Content-Encoding value. It should show gzip or br (Brotli) instead of being empty or missing.

Troubleshooting Common Issues

If compression does not seem to work after making changes, check the following:

  • CDN override: If you use a CDN like Cloudflare, the CDN may handle compression independently of your server settings. Cloudflare enables Gzip by default and offers Brotli as a toggle in the Speed settings.
  • Server module not loaded: On Apache, mod_deflate must be enabled. Contact your hosting provider if you are unsure. On Nginx, the Brotli module requires separate installation.
  • Conflicting rules: Multiple plugins or .htaccess rules trying to set compression can conflict. Check for duplicate mod_deflate blocks in your .htaccess file.
  • Proxy or cache layer: Reverse proxies like Varnish may strip or modify compression headers. Make sure each layer in your stack is configured correctly.

Check your WordPress site now

InspectWP analyzes your WordPress site for security issues, SEO problems, GDPR compliance, and performance — for free.

Analyze your site free