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

2

15

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.

Ladybug answered 11/7, 2010 at 23:58 Comment(0)
S
9

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.

Sadirah answered 20/7, 2010 at 18:10 Comment(1)
I also thought the RFC stated the first entry is the preferred, but couldn't find the specific reference to clarify it. Great info on why you'd choose one over the other though.Ladybug
J
2

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

Johann answered 12/7, 2010 at 0:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.