Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
259 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...