docs.rodeo

MDN Web Docs mirror

Content-Encoding

{{HTTPSidebar}} 

The HTTP Content-Encoding {{Glossary("representation header")}}  lists the encodings and the order in which they have been applied to a resource. This lets the recipient know how to decode the data in order to obtain the original content format described in the {{HTTPHeader("Content-Type")}}  header. Content encoding is mainly used to compress content without losing information about the original media type.

Servers should compress data as much as possible, and should use content encoding where appropriate. Compressing already compressed media types, such as .zip or .jpeg, is usually not appropriate because it can increase the file size. If the original media is already encoded (e.g., as a .zip file), this information is not included in the Content-Encoding header.

When the Content-Encoding header is present, other metadata (e.g., {{HTTPHeader("Content-Length")}} ) refer to the encoded form of the data, not the original resource, unless explicitly stated. Content encoding differs to {{HTTPHeader("Transfer-Encoding")}}  in that Transfer-Encoding handles how HTTP messages themselves are delivered across the network on a hop-by-hop basis.

Header type `{{Glossary("Representation header")}}` 
`{{Glossary("Forbidden header name")}}`  No

Syntax

Content-Encoding: gzip
Content-Encoding: compress
Content-Encoding: deflate
Content-Encoding: br
Content-Encoding: zstd

// Multiple, in the order in which they were applied
Content-Encoding: deflate, gzip

Directives

Examples

Compressing with gzip

On the client side, you can advertise a list of compression schemes that will be sent along in an HTTP request. The {{HTTPHeader("Accept-Encoding")}}  header is used for negotiating content encoding.

Accept-Encoding: gzip, deflate

The server responds with the scheme used, indicated by the Content-Encoding response header.

Content-Encoding: gzip

Whether a server uses compression methods requested by the client depends on server configuration and capabilities.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN