Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP: What is the preferred Accept-Encoding for "gzip,deflate"?

This question is regarding the order of precedence for the media-types of the HTTP Header "Accept-Encoding" when all are of equal weight and has been prompted by this comment on my blog.

Background:

The Accept-Encoding header takes a comma separated list of media-types the browser can accept e.g. gzip,deflate

A quality factor can also be specified to give preference to other media-types e.g. in the case of "gzip;q=.8,deflate", deflate is preferred - but is not relevant to this question. NB: A type with a "q=0" means "not acceptable".

RFC2616 also states that the "most specific reference" for the media-type definition should be weighted first. i.e. "text/html;level=1" should be used over "text/html" - this is not relevant to the question also.

Question:

In the following case, which media-type has precedence?

Accept-Encoding: gzip,deflate

Both types have an equivalent quality factor of 1, and both types are "acceptable" to the browser - so either one could be used. I'd always assumed that the first type entered should be "preferred", but there doesn't seem to be a specific example or preference for this particular case in the RFC.

like image 471
Dave Transom Avatar asked Jul 11 '10 23:07

Dave Transom


People also ask

What is accept-Encoding gzip DEFLATE?

The 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. Note that the server is not obligated to use any compression method.

What is DEFLATE in gzip?

gzip is based on the DEFLATE algorithm, which is a combination of LZ77 and Huffman coding. DEFLATE was intended as a replacement for LZW and other patent-encumbered data compression algorithms which, at the time, limited the usability of compress and other popular archivers.

What is gzip Encoding?

Gzip is a data compression algorithm capable of compressing and decompressing files quickly. The name also refers to two other technologies: the software used to compress and decompress files, and the format those files are stored in.

What is DEFLATE in HTTP?

In HTTP/1.1, Content-encoding: deflate actually refers to the DEFLATE compression algorithm, as defined by RFC 1951, wrapped in the zlib data format, as defined by RFC 1950. However some vendors just implement the DEFLATE algorithm as defined RFC 1951, completely ignoring RFC 1950 (no zlib headers).


2 Answers

There is no client side preference here. Just pick one what you (the server side) would prefer.

like image 77
BalusC Avatar answered Oct 21 '22 03:10

BalusC


I believe somewhere in the RFC, or in a related RFC, it states that the first is preferred for all fields of this format.

However, in the special case of gzip vs deflate, you should probably use deflate if you can due to lower overhead (fewer headers and footers, and although it still has an adler32 checksum, it doesn't have a crc32 on top). Other than that they are exactly the same. The actual data is compressed in the same way for both. This means deflate is both faster and produces a smaller output. Both of these become far more important on a page under heavy load. Most of the extra headers in gzip are things like unix style file permissions, which are useless in this context anyway.

Really, clients should want to be served gzip due to reliability and servers should want to serve deflate due to performance. The extra overhead is much more important when it happens thousands of times a second than when it happens once for every page you load.

On my own sites I check for deflate first and use that if I can, then I check for gzip. If I can't use either, I just send in plain text. I don't know what language you are using but it's about 5 lines of ASP.NET to do that.

like image 32
GEorge Helyar Avatar answered Oct 21 '22 05:10

GEorge Helyar