Skip to the page

HTTP semantics, caching and delivery · mid

Compression: gzip, Brotli, zstd and dictionaries

Text responses (HTML, CSS, JS, JSON, SVG) should be compressed with Brotli or zstd (gzip as fallback), chosen through Accept-Encoding and announced with Content-Encoding plus Vary: Accept-Encoding, while already-compressed formats like JPEG, AVIF and WOFF2 should not be compressed again.

The notes

What you must know

  • The browser sends Accept-Encoding: gzip, deflate, br, zstd; the server picks one and sends Content-Encoding and Vary: Accept-Encoding.
  • Brotli usually beats gzip by 15 to 25% on text. Use maximum level (11) for static files at build time and a medium level for dynamic responses (high levels are slow to compress).
  • zstd: similar ratio to Brotli with faster compression. Chrome 123+, Firefox 126+, Safari 26.3+ (only on newer OS versions). Browsers advertise br and zstd only over HTTPS.
  • Compression dictionaries (RFC 9842, Chrome 130+): a previous version of a file is used as a dictionary to compress the next version (dcb/dcz), so updates download only the difference. Not in Safari or Firefox yet.
  • Do not compress images, video, WOFF2 or zip files: they are already compressed and may get larger.
  • Compression reduces transfer size, not parse/execute cost; a 300 KB minified bundle is still 300 KB of JS to parse.

The red pen

Common traps: mistake → fix

  • Mistake: "Gzip everything, including images"

    Fix: already-compressed formats gain nothing and waste CPU.

  • Mistake: "Compression fixes a big bundle"

    Fix: it shrinks the download, but the browser still parses the full code.

  • Mistake: "Forget Vary: Accept-Encoding"

    Fix: a CDN may serve a Brotli response to a client that can't decode it.

Easy to hard

Questions interviewers ask, easy to hard

  1. How does the browser and server agree on compression?
  2. Gzip vs Brotli vs zstd: what would you configure today?
  3. Why compress static files at build time at a high level but dynamic responses at a lower level?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview