content

Content-Encoding

Indicates that the body has been transformed with one or more compressions and must be decoded in reverse order to recover the original payload. Negotiated via the client's Accept-Encoding.

Content-Encoding: <coding>[, <coding>...]  (gzip, br, deflate, zstd, identity — applied in order)

Common directives / values

Directive Purpose
gzip Widely supported LZ77+Huffman compression (RFC 1952).
br Brotli — better ratio than gzip on text; broadly supported over HTTPS.
deflate Raw zlib deflate — history of interop bugs; prefer gzip.
zstd Zstandard — very fast, good ratio; growing browser support.
identity No encoding applied — explicit way to opt out.

Examples

Content-Encoding: gzip

Standard gzipped HTML/JSON/JS response.

Content-Encoding: br

Brotli-compressed asset for HTTPS clients that advertised 'br' in Accept-Encoding.

Content-Encoding: gzip\nVary: Accept-Encoding

Always Vary on Accept-Encoding when serving compressed variants to keep caches honest.

Content-Encoding: identity

Explicitly uncompressed — useful for Range requests where compression would break offsets.

Gotcha

Applying two encodings (e.g. gzip and br) yields the header 'Content-Encoding: br, gzip' meaning 'brotli-then-gzip'; forgetting the order breaks decoding. Never gzip content twice by accident (Nginx + upstream) — clients decompress once and see garbage.

Related headers

← All HTTP headers · HTTP status codes · Fix CORS errors