Google Page Speed Addon通知我:

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

最佳答案

它允许缓存根据浏览器是否请求GZIP编码来提供页面的不同缓存版本。如果指示的 header 中有任何变化,则variable header 指示高速缓存存储页面的不同版本。

就目前情况而言,缓存中将有一个页面的副本(可能是压缩的)。假设它是压缩版本:如果有人请求资源但不支持gzip编码,则会为他们提供错误的内容。

10-07 19:24
查看更多