Performance & Debugging

Enable Gzip and Brotli Compression Safely

Reduce text response transfer size while avoiding double compression, poor MIME coverage and unnecessary CPU overhead.

HTTP compression reduces the number of bytes needed to transfer text-based resources. Gzip is widely supported and Brotli can provide better compression for many web assets. The best configuration depends on the web server, CDN and client support.

Select suitable content types

HTML, CSS, JavaScript, JSON, XML and SVG text are common compression candidates. JPEG, PNG, WebP, AVIF, ZIP and other already-compressed formats usually gain little and may waste CPU. Configure the server or CDN to compress the intended MIME types rather than every response indiscriminately.

Negotiate supported encodings

Clients advertise accepted encodings. The server should select an encoding supported by the client and return the correct Content-Encoding and Vary headers. Avoid compressing a response twice when both the origin and edge layer attempt to apply compression.

Balance compression and CPU

Higher compression levels consume more CPU and may increase latency under load. Static assets can often be compressed ahead of time, while dynamic responses need settings that balance CPU and transfer size. Measure the effect under realistic traffic.

Verify end to end

Inspect response headers and compare compressed and uncompressed sizes. Test through the public CDN or reverse proxy, not only directly against the origin. Confirm that caches distinguish representations when required.

Checklist

  • Compress text-based response types.
  • Avoid recompressing already-compressed media.
  • Set correct Content-Encoding and Vary behavior.
  • Prevent origin and CDN double compression.
  • Measure CPU, latency and transfer-size changes.
Share this page Help other developers discover this resource.