gzip universal; Brotli ~15–25% smaller on text. Static — max level at build; dynamic — low level on the fly. Vary: Accept-Encoding mandatory.
Разбор
gzip (DEFLATE) — universal, every client/proxy, fast enough per-request on dynamic.
Brotli (br) — ~15–25% smaller than gzip on text, built-in web string dictionary, all modern browsers on HTTPS.
Level vs cost:
- Static assets — compress once at deploy max level (
brotli -q 11, gzip -9). Serve app.js.br forever.
- Dynamic JSON — on the fly; max Brotli melts CPU. gzip or Brotli level 4–5 beats gzip ratio at similar speed.
Content-Encoding (resource is compressed) vs Transfer-Encoding (hop-by-hop). Vary: Accept-Encoding — cache won't serve Brotli to gzip-only client.
Итог
Precompress statics at max; dynamic at moderate level; always Vary on encoding.