For compression, end-to-end compression is where the largest performance improvements of Web sites reside. End-to-end compression refers to a compression of the body of a message that is done by the server and will last unchanged until it reaches the client. Whatever the intermediate nodes are, they leave the body untouched.
All modern browsers and servers do support it and the only thing to negotiate is the compression algorithm to use. These algorithms are optimized for text. In the 1990s, compression technology was advancing at a rapid pace and numerous successive algorithms have been added to the set of possible choices. Nowadays, only two are relevant: gzip
, the most common one, and br
the new challenger.
To select the algorithm to use, browsers and servers use proactive content negotiation. The browser sends an Accept-Encoding
header with the algorithm it supports and its order of precedence, the server picks one, uses it to compress the body of the response and uses the Content-Encoding
header to tell the browser the algorithm it has chosen. As content negotiation has been used to choose a representation based on its encoding, the server must send a Vary
header containing at least Accept-Encoding
alongside this header in the response; that way, caches will be able to cache the different representations of the resource.
As compression brings significant performance improvements, it is recommended to activate it for all files, but already compressed ones like images, audio files and videos.
Apache supports compression and uses mod_deflate; for Nginx there is ngx_http_gzip_module; for IIS, the <httpCompression>
element.