HTTP:“gzip,deflate”的首选接受编码是什么?
这个问题是关于 HTTP 标头“Accept-Encoding”的媒体类型的优先顺序,当所有内容都具有相同的权重时,并且已由 此评论在我的博客上。
背景:
Accept-Encoding 标头采用逗号分隔的浏览器可以接受的媒体类型列表,例如 gzip,deflate
还可以指定质量因子以优先考虑其他媒体类型媒体类型 例如,在“gzip;q=.8,deflate”的情况下,deflate 是首选 - 但与此问题无关。注意:带有“q=0”的类型表示“不可接受”。
RFC2616 还指出媒体类型的“最具体的参考”首先应该对定义进行加权。即“text/html;level=1”应该用于“text/html” - 这也与问题无关。
问题:
在以下情况下,哪种媒体类型优先?
Accept-Encoding: gzip,deflate
两种类型的品质因数均为 1,并且浏览器都“可接受” - 因此可以使用其中任何一种。我一直认为输入的第一个类型应该是“首选”,但在 RFC。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信 RFC 或相关 RFC 中的某处指出,对于这种格式的所有字段,第一个是首选。
但是,在 gzip 与 deflate 的特殊情况下,如果可以的话,您可能应该使用 deflate,因为它的开销较低(页眉和页脚较少,尽管它仍然具有 adler32 校验和,但顶部没有 crc32)。除此之外,它们完全相同。两者的实际数据以相同的方式压缩。这意味着放气速度更快并且产生的输出更小。对于负载较重的页面,这两者都变得更加重要。 gzip 中的大多数额外标头都是类似于 unix 样式文件权限之类的东西,无论如何,它们在这种情况下都是无用的。
实际上,由于可靠性,客户端应该希望提供 gzip 服务,而由于性能,服务器应该希望提供 deflate 服务。当每秒发生数千次时,额外的开销比加载每个页面时发生一次要重要得多。
在我自己的网站上,我首先检查 deflate 并使用它(如果可以的话),然后检查 gzip。如果我都不能使用,我就以纯文本发送。我不知道你使用的是什么语言,但大约需要 5 行 ASP.NET 来做到这一点。
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.
这里没有客户端偏好。只需选择您(服务器端)喜欢的一个即可。
There is no client side preference here. Just pick one what you (the server side) would prefer.