Brotli / gzip compression

Squeezing text responses before they cross the wire, so the browser downloads a fraction of the bytes and unpacks them on arrival.

turn on compressionmake my responses smallergzip my sitebrotlycontent-encoding brzip the files before sending themwhy is my JS so big over the wireshrink the download size without deleting code

See it

Live demo coming soon

What it is

Text compresses beautifully, so servers squeeze HTML, CSS, JS, JSON, and SVG before sending them and the browser unpacks them on arrival. The browser advertises what it can handle with 'Accept-Encoding', the server answers with 'Content-Encoding: br' or 'gzip'. A typical JS bundle drops to roughly a quarter of its size with gzip, and Brotli shaves another 15 to 20 percent off that thanks to a built-in dictionary of common web text.

Two modes matter. Static compression happens at build time: you precompress files at Brotli's maximum quality (level 11), which is slow but paid for once. Dynamic compression happens per request for generated HTML and API responses, where you want a middling level (4 to 6) so CPU time does not cost you more than the bytes saved. Most hosts and CDNs do both for you, and the honest first move is to check the response headers before installing anything.

Gotcha: compressing already-compressed formats is pure waste. JPEG, PNG, WebP, AVIF, MP4, and WOFF2 are compressed internally, so running them through gzip burns CPU to save nothing (occasionally it makes them bigger). Any negotiated response also needs 'Vary: Accept-Encoding', or a shared cache will store one variant and hand a Brotli body to a client that only speaks gzip. Also watch for double compression at two layers, and for a proxy that strips 'Accept-Encoding' upstream and silently kills compression for everyone.

Ask AI for it

Configure whichever server or build tool this repo actually uses to serve precompressed variants. Precompress static assets (JS, CSS, HTML, SVG, JSON) at build time to '.br' at Brotli quality 11 and '.gz' at gzip level 9, and serve the right variant according to the request's 'Accept-Encoding', falling back to the uncompressed file. Every negotiated response must carry the matching 'Content-Encoding' and 'Vary: Accept-Encoding', otherwise a shared cache will serve a Brotli body to a client that cannot read it. Compress dynamic responses on the fly at Brotli quality 4 to 5. Skip already-compressed types entirely: JPEG, PNG, WebP, AVIF, MP4, WOFF2. Then verify the three cases separately with curl, sending 'Accept-Encoding: br', then 'gzip', then none at all, and show me the status, 'Content-Encoding', and 'Vary' on each.

You might have meant

cdncache control cache ttlimmutable asset content hashingvary headerhttp 3 quic