Accept-Encoding
Description
The Accept-Encoding
request header is an HTTP header used by clients (such
as web browsers) to indicate the content encoding (compression algorithms) they
support. This allows servers to return responses in a compressed format,
reducing the size of transferred data and improving load times.
Compression is an essential part of web performance optimization, as it
minimizes bandwidth usage and speeds up content delivery. Common encoding
formats include gzip, deflate, and br (Brotli). The server processes
this header and selects a supported encoding before responding with the
Content-Encoding
response header.
Syntax
The Accept-Encoding
header follows this syntax:
The <encoding>
values can include:
gzip
– Gzip compressiondeflate
– Zlib-based compressionbr
– Brotli compression (used mainly with HTTPS)identity
– No compression (default behavior)*
– Any available encoding supported by the server
Examples
Basic Usage in HTTP Requests
When a client supports multiple compression formats, it can send:
If the client only supports gzip, it will send:
Server Response Example
The server inspects the Accept-Encoding
header and responds with a compressed
version of the resource if supported:
Summary
The Accept-Encoding
request header is a crucial component of modern web
performance, allowing clients to request compressed content and reduce data
transfer sizes. By leveraging this header, servers can improve page load times
and optimize bandwidth usage. Proper implementation of content encoding enhances
user experience and overall web efficiency.