// http header · response header

Content-Encoding

Compression applied to the body

What the Content-Encoding header does

Content-Encoding names the compression applied to the response body, such as gzip or br. The client reverses it before reading the body. It's chosen from what the client offered in Accept-Encoding.

Example

Content-Encoding: gzip

Content-Encoding in practice

Compressed response

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Encoding: br
Vary: Accept-Encoding

Common Content-Encoding questions and problems

Content-Encoding vs Transfer-Encoding?

Content-Encoding describes compression applied to the resource itself and stays with it. Transfer-Encoding (such as chunked) applies to the connection hop only.

Why do I see garbled output?

The body is compressed but the client was not asked to decompress it, or it was compressed twice. Check that only one layer (origin or CDN) compresses and that the header matches the real encoding.

Is a .gz file the same as Content-Encoding: gzip?

No. A file that is itself a gzip archive is served as application/gzip. Content-Encoding: gzip means the transport compressed a resource, such as a normal HTML page.

Content-Encoding vs related headers

  • Accept-Encoding: Accept-Encoding is what the client can decompress. Content-Encoding is what the server used.
  • Content-Type: Content-Type names the format after decompression.

Where it's used

Content-Encoding is a response header. Response headers are sent by the server to describe the response and tell the client how to handle it.

Other response headers