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

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

问题描述

这个问题是关于当所有都具有相等权重且由此评论在我的博客上。

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 浏览器可以接受eg gzip,deflate

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,但是与此问题不相关。 NB:具有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 vs deflate ,你应该使用deflate,如果你可以减少开销(更少的页眉和页脚,虽然它仍然有一个adler32校验和,它没有crc32顶部)。除此之外,他们是完全一样的。对于两者,实际数据以相同的方式压缩。这意味着放气更快,产生更小的输出。这两者在重负载下的页面上变得更重要。

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服务,所以gzip中的大多数额外的头文件都是unix样式文件权限,并且服务器应该由于性能而需要服务泄露。

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。如果我不能使用,我只是发送纯文本。我不知道你使用什么语言,但它是关于ASP.NET的5行。

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”的首选Accept-Encoding是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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