How to Enable Gzip or Brotli Compression on Your Website
If your server returns HTML, CSS or JavaScript without a Content-Encoding header, every visitor downloads the full uncompressed bytes, often 3 to 5 times more than necessary. This guide shows how to turn on Brotli (with Gzip as a fallback) at your CDN or web server. By the end, your homepage and your own text files will be served compressed, and you will have checked the result with curl and browser DevTools.

Why it matters
Text files compress very well. A 120 KB HTML page or JavaScript bundle typically shrinks to 20 to 30 KB with Brotli. Smaller transfers reduce Time to First Byte overhead, Largest Contentful Paint and total blocking on slow mobile connections.
These metrics feed Core Web Vitals, which Google uses as a page experience signal. Crawlers and AI bots also fetch compressed pages faster, so they can crawl more of your site within the same budget. Uncompressed HTML on the homepage is treated as a hard failure.
Any first-party CSS, JS, JSON or SVG files over about 2 KB that are still uncompressed produce a warning.
What you need
Step-by-step fix
Measure what your server sends today
Request your homepage the same way a browser does, by sending an Accept-Encoding header. Without that header, curl gets the uncompressed version and you will see a false failure. Run the command below for the homepage and for one large CSS or JS file from your site.
If you see no content-encoding line, or the value is identity, compression is off for that response.
curl -s -o /dev/null -D - -H "Accept-Encoding: br, gzip, zstd" https://example.com/ | grep -iE "content-encoding|content-type|vary|cache-control" curl -s -o /dev/null -D - -H "Accept-Encoding: br, gzip" https://example.com/assets/app.js | grep -i content-encoding
Find out which layer serves the response
Compression has to be turned on at whichever layer actually sends the bytes to the browser. Check the response headers to identify it:
server: cloudflareor acf-rayheader means Cloudflare.x-vercel-idmeans Vercel.x-served-bymeans Fastly.server: nginxorserver: Apachemeans your own server.
If a CDN is in front of your server, enabling compression at the CDN is usually enough. You still need the origin settings for any assets that bypass the CDN, such as files on a separate subdomain or a storage bucket.
Enable compression at your CDN
Most CDNs compress text by default, but rules or plan settings can switch it off.
- Cloudflare: Brotli and Gzip are applied automatically to eligible content types. Go to Rules > Compression Rules and make sure no rule sets compression to "Disable" for your HTML, CSS or JS. Also check that no Page Rule or Configuration Rule bypasses it.
- Fastly: Enable Brotli/Gzip under Settings > Compression.
- AWS CloudFront: Set Compress objects automatically = Yes on each behavior, and use a cache policy with Gzip and Brotli enabled.
Turn on Gzip and Brotli in Nginx
Add the block below inside the http { } block of /etc/nginx/nginx.conf, or in a file under /etc/nginx/conf.d/. Do not list text/html in gzip_types, because Nginx always compresses HTML when gzip is on. For Brotli, install the module first:
- On Debian/Ubuntu:
sudo apt install libnginx-mod-http-brotli-filter libnginx-mod-http-brotli-static
Then uncomment the brotli lines. Test the config and reload Nginx.
gzip on; gzip_vary on; gzip_proxied any; gzip_comp_level 5; gzip_min_length 1024; gzip_types text/plain text/css text/javascript application/javascript application/json application/ld+json application/manifest+json application/xml application/rss+xml image/svg+xml font/ttf font/otf; # Brotli (requires ngx_brotli module) # brotli on; # brotli_comp_level 5; # brotli_types text/html text/plain text/css text/javascript application/javascript application/json application/ld+json application/manifest+json application/xml application/rss+xml image/svg+xml font/ttf font/otf; # then: sudo nginx -t && sudo systemctl reload nginx
Or turn it on in Apache / .htaccess
First enable the modules with sudo a2enmod deflate brotli headers && sudo systemctl reload apache2. On shared hosting, ask your host to confirm mod_deflate is active. htaccess` in your site root.
Apache will use Brotli for browsers that support it and fall back to Gzip for the rest.
<IfModule mod_brotli.c> AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml font/ttf font/otf </IfModule> <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml font/ttf font/otf </IfModule> <IfModule mod_headers.c> Header append Vary Accept-Encoding </IfModule>
Fix individual files that are still uncompressed
After the homepage passes, look for leftover first-party CSS, JS, JSON or SVG files over about 2 KB with no Content-Encoding. Common causes:
- Files on object storage such as S3, R2 or GCS buckets. These do not compress on the fly, so either serve them through your CDN or upload pre-compressed
.br/.gzversions with the matchingContent-Encodingmetadata. - A Node/Express app with no compression. Add the
compressionmiddleware, or let your proxy do it. - Wrong Content-Type. A file sent with an untyped MIME type is skipped by gzip_types and CDN rules.
Images such as JPEG, PNG, WebP and AVIF are already compressed and do not need this.
// Express example
import compression from 'compression';
app.use(compression({ threshold: 1024 }));Purge caches and re-test
Purge your CDN cache, plus any page cache plugin or server cache, so that fresh, compressed copies are stored. Then repeat the curl commands from step 1 for the homepage and two or three CSS/JS files. Each should show content-encoding: br (or gzip/zstd) and vary: Accept-Encoding.
Finally, re-run the audit to confirm both the homepage check and the per-file check pass.
curl -s -o /dev/null -D - -H "Accept-Encoding: br, gzip" https://example.com/ | grep -i content-encoding # expected: content-encoding: br
Platform-specific notes
WordPress
Compression happens at the server or host level, not in WordPress itself. On Apache hosts, use the .htaccess block from step 5. WP Rocket and W3 Total Cache can write Gzip rules for you, but only if mod_deflate is installed. On LiteSpeed servers, LiteSpeed handles Brotli/Gzip natively; enable it in your host's panel or the LiteSpeed Cache plugin. Managed hosts like Kinsta and WP Engine compress by default, so a failure there usually points to a plugin or proxy adding `no-transform`.
Shopify
Shopify's CDN compresses storefront HTML, theme CSS and JS automatically, and you cannot change server settings. If the check fails, test the canonical myshopify or custom domain directly. Then check whether a reverse proxy or third-party app in front of the store is stripping compression or serving uncompressed files from its own host.
Next.js
`next start` applies gzip by default (`compress: true` in next.config.js). Vercel and Netlify serve Brotli automatically at the edge. If you self-host behind Nginx or a CDN, set `compress: false` in next.config.js and let the proxy compress with Brotli, so files are not compressed twice. Make sure `gzip_proxied any` is set in Nginx.
Cloudflare
Compression is on by default, and there is no longer a separate Brotli toggle under Speed. Check **Rules > Compression Rules** for anything that disables it. Also note that Cloudflare will not compress responses carrying `Cache-Control: no-transform` or unrecognised content types. Cloudflare can also deliver Zstandard to supporting browsers.
Nginx behind a load balancer
AWS ALB and Google Cloud Load Balancer forward requests with headers that Nginx treats as proxied. Without `gzip_proxied any`, Nginx returns uncompressed responses, even though a direct curl to the server shows gzip.
Check that it worked
✅ How to verify
- Run `curl -s -o /dev/null -D - -H "Accept-Encoding: br, gzip" https://example.com/` and confirm a `content-encoding: br` or `gzip` line.
- In Chrome DevTools, open Network, reload with cache disabled, then right-click the column header and add **Content-Encoding**. Every first-party document, CSS and JS row should show br, gzip or zstd.
- Compare the **Size** (transferred) and **Resource** (uncompressed) values in DevTools. Compressed text files should transfer at roughly 20–35% of their full size.
- Re-run the audit to confirm the homepage check and the uncompressed-file warning are both cleared.
⚠️ Common mistakes
- Testing with plain `curl https://example.com` without an Accept-Encoding header, then concluding compression is broken.
- Adding .htaccess or plugin rules without mod_deflate/mod_brotli actually loaded, so the IfModule blocks silently do nothing.
- Leaving `Cache-Control: no-transform` on responses, or serving JS/CSS with a generic Content-Type, which stops CDNs and gzip_types from compressing.
- Forgetting to purge the CDN and page cache, so old uncompressed copies keep being served after the config change.
Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.
Check my site freeFAQ
Should I use Brotli or Gzip?
Use both. Brotli produces files about 15–20% smaller than Gzip for HTML, CSS and JS, and every current browser supports it over HTTPS. Keep Gzip enabled as a fallback for older clients and bots. The server picks the best option based on the browser's Accept-Encoding header.
Does Gzip or Brotli compression help SEO?
Indirectly, yes. Compression is not a ranking factor on its own, but it cuts transfer size. That improves load metrics like LCP, which feed Core Web Vitals, and it lets crawlers fetch pages faster.
Should I compress images and fonts too?
No for JPEG, PNG, WebP, AVIF and WOFF2. They are already compressed, so Gzip adds CPU cost for no gain. Do compress SVG, JSON, XML, and older TTF/OTF fonts, because they are text or uncompressed binary.
What compression level should I use?
For on-the-fly compression, level 4–6 for both Gzip and Brotli gives most of the size savings at low CPU cost. Save the maximum levels (Gzip 9, Brotli 11) for files you pre-compress at build time and serve as static .br/.gz files.
How to Fix Browser Caching Headers on Static Assets
How to Fix Unminified CSS and JavaScript Files on Your Site
How to Fix Next-Gen Image Formats: Serve WebP and AVIF
How to Fix Render-Blocking Resources on Your Website
How to Fix Oversized Images and Cut Homepage Image Weight
How to Fix Total Page Weight: Get Your Homepage Under 2 MB