HTTP compression (Web server compression)

Last updated 17 June 2026 3 min

Compression is the process of reducing the size of files sent from a web server to a browser. Smaller files = faster page loads, lower bandwidth costs, and better Core Web Vitals scores. For text-based assets (HTML, CSS, JavaScript, JSON, SVG), compression typically cuts file size by 70–90%.

How compression works

When a browser requests a page, it tells the server which compression formats it accepts via the Accept-Encoding header:

Accept-Encoding: gzip, deflate, br

If the server is configured to compress, it picks a supported method, compresses the file on the fly (or serves a pre-compressed version), and sends back a Content-Encoding header indicating which format it used. The browser then decompresses the file before rendering.

It is important to note that requesting compressed content does not automatically make the server provide it. The compression program must be configured on the web hosting in order for this to happen.

The three main formats

  • Gzip — the long-standing default. Supported by every browser and server. Excellent compression-to-CPU ratio.
  • Brotli (br) — developed by Google and supported in all modern browsers. Compresses around 20% smaller than Gzip for text assets, at the cost of slightly higher CPU usage during compression. Pre-compressed Brotli files are common.
  • Deflate — older, less efficient than Gzip. Used much less often these days.

Brotli is the modern preferred choice for text. Enable both, serving Brotli when supported and falling back to Gzip.

What to compress

  • Text-based files: HTML, CSS, JavaScript, JSON, XML, SVG, plain text.
  • Web fonts: WOFF2 is already compressed; WOFF and TTF benefit from server-side compression.

What NOT to compress

  • Images (JPEG, PNG, WebP, AVIF) — already compressed at the format level. Recompressing wastes CPU and produces no savings.
  • Video and audio — same reason.
  • Pre-compressed archives (ZIP, GZ, etc.).

Recompressing these wastes CPU for no size benefit.

How to enable web server compression

  • Apachemod_deflate for Gzip, mod_brotli for Brotli, configured via .htaccess or httpd.conf.
  • Nginx — built-in gzip on; and the ngx_brotli module.
  • CDNs (Cloudflare, Fastly, Akamai) — usually a single toggle in the dashboard. Often the easiest path.
  • Compression is enabled by default on many hosting providers (WP Engine, Kinsta, Shopify).

Verifying compression is working

  • Browser DevTools → Network tab → click any request → check the Response Headers for Content-Encoding: br or Content-Encoding: gzip.
  • Online tools like HTTP Compression Test and PageSpeed Insights will flag uncompressed text assets.
  • curl -I -H "Accept-Encoding: gzip, br" https://example.com from the command line.

Why it matters for SEO

Page speed is a ranking factor through Core Web Vitals (specifically Largest Contentful Paint, which is heavily influenced by file size and download time). Compression is one of the lowest-effort, highest-impact performance optimisations available — usually a configuration change rather than a development project.

Common issues

  • Compression enabled for HTML but not CSS/JS.
  • CDN compression enabled but origin server compression disabled, so cache misses are served uncompressed.
  • Dynamic compression configured, but not for static assets.

Disclaimer: All information contained herein is for informational purposes only. It is not advice or instructional.