变化:接受编码是什么意思?
谷歌页面速度插件告诉我:
The following publicly cacheable, compressible resources should have a "Vary: Accept-Encoding" header:
//some .js and .css files
我不明白这意味着什么。我已经像这样压缩了这些文件:
if (encodings.Contains("gzip") || encodings == "*")
{
app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
这一切似乎都有效。为什么需要 Vary: Accept-Encoding
?
the google page speed addon informs me:
The following publicly cacheable, compressible resources should have a "Vary: Accept-Encoding" header:
//some .js and .css files
I don't understand what this means. I've already compressed these files like so:
if (encodings.Contains("gzip") || encodings == "*")
{
app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
And this all seems to work. Why is having Vary: Accept-Encoding
necessary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它允许缓存根据浏览器是否请求 GZIP 编码来提供页面的不同缓存版本。如果指示的标头中有任何变化,则变化标头指示缓存存储页面的不同版本。
就目前情况而言,缓存中将存在该页面的一份(可能是压缩的)副本。假设它是压缩版本:如果有人请求资源但不支持 gzip 编码,他们将收到错误的内容。
It is allowing the cache to serve up different cached versions of the page depending on whether or not the browser requests GZIP encoding or not. The vary header instructs the cache to store a different version of the page if there is any variation in the indicated header.
As things stand, there will be one (possibly compressed) copy of the page in cache. Say it is the compressed version: If somebody requests the resource but does not support gzip encoding, they'll be served the wrong content.
变化:Accept-Encoding 通知服务器在缓存所请求资源的表示方面的行为。如果收到对先前缓存的资源的新请求,则将从缓存中提供服务,除非新请求的 Accept-Encoding 标头与先前缓存的表示不同,此时该请求将被视为新请求,并且不会从缓存中提供服务。
** 编辑 **
正如花费者指出的那样 - 如果您从缓存中提供压缩文件,并且客户端不接受您的压缩机制,他们将得到一页垃圾,所以是的,这是必要的。不过,通过正常测试,您不一定会注意到差异。
请参阅http://www.w3.org/Protocols/rfc2616/ rfc2616-sec14.html#sec14.44 和 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14 .html#sec14.3
Vary: Accept-Encoding informs the behavior of the server with respect to caching the representation of the requested resource. If a new request for a previously cached resource is received, it will be served from the cache unless the Accept-Encoding header of the new request is different from the previously cached representation, at which point the request will be treated as a new request and will not be served from cache.
** EDIT **
As spender points out - if you're serving a compressed file from cache and the client doesn't accept your compression mechanism they'll get a page of junk, so yes, it's necessary. You wouldn't necessarily notice the difference through normal testing, though.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44 and http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3