HTTP:“gzip,deflate"的首选接受编码是什么? [英] HTTP: What is the preferred Accept-Encoding for "gzip,deflate"?

查看:43
本文介绍了HTTP:“gzip,deflate"的首选接受编码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于当 all are equal weight 并且由 这篇评论在我的博客上.

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.

Accept-Encoding 标头采用逗号分隔的 media-types 列表,浏览器可以接受,例如gzip,放气

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

品质因数也可以被指定以优先考虑其他媒体类型,例如在gzip;q=.8,deflate"的情况下,首选 deflate - 但 与此问题无关.注意:带有q=0"的类型表示不可接受".

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 还指出最具体的参考"媒体类型定义应首先加权.即text/html;level=1"应该用在text/html"之上——这也与问题无关.

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.

在以下情况下,哪种媒体类型优先?

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

Accept-Encoding: gzip,deflate

这两种类型都有一个等效的品质因数 1,并且这两种类型对于浏览器都是可接受的"——因此可以使用任何一种.我一直认为输入的第一种类型应该是首选",但在 RFC.

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.

推荐答案

我相信在 RFC 或相关 RFC 中的某处,它声明第一个是这种格式的所有字段的首选.

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

但是,在 gzip 与 deflate 的特殊情况下,如果可以的话,您可能应该使用 deflate,因为开销较低(页眉和页脚较少,虽然它仍然有 adler32 校验和,但它没有顶部的 crc32).除此之外,它们完全相同.两者的实际数据以相同的方式压缩.这意味着放气速度更快,输出更小.这两者在重负载下的页面上变得更加重要.gzip 中的大多数额外标头都是诸如 unix 样式文件权限之类的东西,无论如何在这种情况下它们是无用的.

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.

确实,出于可靠性考虑,客户端应该希望使用 gzip 服务,而出于性能考虑,服务器应该希望使用 deflate 服务.额外的开销在每秒发生数千次时比在您加载的每个页面发生一次时更重要.

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.

在我自己的网站上,我首先检查 deflate,如果可以的话,我会使用它,然后检查 gzip.如果我不能使用,我只是发送纯文本.我不知道您使用的是什么语言,但它大约需要 5 行 ASP.NET 来做到这一点.

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.

这篇关于HTTP:“gzip,deflate"的首选接受编码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆