Accept-Encoding header
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The HTTPAccept-Encodingrequest andresponse header indicates the content encoding (usually a compression algorithm) that the sender can understand.In requests, the server usescontent negotiation to select one of the encoding proposals from the client and informs the client of that choice with theContent-Encoding response header.In responses, it provides information about which content encodings the server can understand in messages to the requested resource, so that the encoding can be used in subsequent requests to the resource.For example,Accept-Encoding is included in a415 Unsupported Media Type response if a request to a resource (e.g.,PUT) used an unsupported encoding.
Even if both the client and the server support the same compression algorithms, the server may choose not to compress the body of a response if theidentity value is also acceptable.This happens in two common cases:
- The data is already compressed, meaning a second round of compression will not reduce the transmitted data size, and may actually increase the size of the content in some cases.This is true for pre-compressed image formats (JPEG, for instance).
- The server is overloaded and cannot allocate computing resources to perform the compression. For example, Microsoft recommends not to compress if a server uses more than 80% of its computational power.
As long as theidentity;q=0 or*;q=0 directives do not explicitly forbid theidentity value that means no encoding, the server must never return a406 Not Acceptable error.
Note:IANA maintainsa list of official content encodings.Thebzip andbzip2 encodings are non-standard, but may be used in some cases, particularly for legacy support.
| Header type | Request header,Response header |
|---|---|
| Forbidden request header | Yes |
In this article
Syntax
Accept-Encoding: gzipAccept-Encoding: compressAccept-Encoding: deflateAccept-Encoding: brAccept-Encoding: zstdAccept-Encoding: dcbAccept-Encoding: dczAccept-Encoding: identityAccept-Encoding: *// Multiple algorithms, weighted with the quality value syntax:Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5Directives
gzipA compression format that uses theLempel-Ziv coding (LZ77) with a 32-bit CRC.
compressA compression format that uses theLempel-Ziv-Welch (LZW) algorithm.
deflateA compression format that uses thezlib structure with thedeflate compression algorithm.
brA compression format that uses theBrotli algorithm.
zstdA compression format that uses theZstandard algorithm.
dcbExperimentalA format that uses theDictionary-Compressed Brotli algorithm. SeeCompression Dictionary Transport.
dczExperimentalA format that uses theDictionary-Compressed Zstandard algorithm. SeeCompression Dictionary Transport.
identityIndicates the identity function (that is, without modification or compression). This value is always considered as acceptable, even if omitted.
*(wildcard)Matches any content encoding not already listed in the header. This is the default value if the header is not present. This directive does not suggest that any algorithm is supported but indicates that no preference is expressed.
;q=(qvalues weighting)Any value is placed in an order of preference expressed using a relativequality value calledweight.
Examples
>Default Accept-Encoding values
Browser navigation typically has the followingAccept-Encoding request header value:
GET /en-US/ HTTP/2Host: developer.mozilla.orgAccept-Encoding: gzip, deflate, br, zstdWeighted Accept-Encoding values
The following header showsAccept-Encoding preferences using a quality value between0 (lowest priority) and1 (highest-priority).Brotli compression is weighted at1.0, makingbr the client's first choice, followed bygzip at0.8 priority, and then any other content encoding at0.1:
Accept-Encoding: br;q=1.0, gzip;q=0.8, *;q=0.1Specifications
| Specification |
|---|
| HTTP Semantics> # field.accept-encoding> |
| Zstandard Compression and the 'application/zstd' Media Type> # name-content-encoding> |
Browser compatibility
See also
415 Unsupported Media Type- HTTPcontent negotiation
- A header with the result of the content negotiation:
Content-Encoding - Other similar headers:
TE,Accept,Accept-Language - Brotli compression
- GZip compression
- Zstandard compression
- Compression Dictionary Transport guide