2

I have tried a tool to measure the speed of my web site. It is Pingdom https://tools.pingdom.com

There is an answer I do not understand "The following publicly cacheable, compressible resources should have a "Vary: Accept-Encoding" header: https://www.example.com/"

Can anyone explain what is that in a simple way and how can I improve it?

If I understand that is related to the way files are compressed. My server does not accept Gzip. It works well with deflate. I put that code in the .htaccess:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

It works well for Google page speed. But it seems that Pingdom still gives an error.

  • The webserver should do this automatically, but I remember seeing something on REDbot's blog about a bug in some server. You may need to add the Vary header manually. – Oskar Skog Jul 21 '17 at 17:17
3

What is it?

The Vary HTTP response header tells user agents (clients) that the server's response can vary if the client changes any of the mentioned request headers.

Vary: Accept-Encoding

This means that if the browser sends a different value in the Accept-Encoding request header, the server might send a different response.
(It should be noted that the Accept-Encoding header says which compression algorithms the browser supports, character encodings are called charsets in HTTP.)


The reason why the header is ever needed is that there can be a cache between the user agent (browser) and the server, and that cache needs to know that the same page can have different content for different user agents. If the server didn't send a Vary header, an intermediary cache could cache a "weird" variant of a page and serve it to everybody, examples:

  • Sending a "mobile page" to desktops.

  • Sending the page compressed with an uncommon/unsupported compression method.

  • Sending the page in a language you don't speak.

Failing to send the Vary header can cause any intermediary cache to ruin your site.


Some examples of other headers that are ¿commonly? mentioned in the Vary header:

  • User-Agent: Commonly used by sites that serve separate mobile and desktop pages on the same URLs. (Some search engines, including Google, require that you use the Vary header if you use this method.)

  • Accept-Language: An internationalized site can use the Accept-Header sent by the browser.


How to improve?

Honestly: It's not the most important Vary header to have. Most browsers support gzip, so it's unlikely that you actually need to implement it.

But I wouldn't say that, would I. I like being pedantic about these kinds of things, so I would suggest you take a look at this question at Stackoverflow that asks how to implement it.

  • I updated my question. I am not sure if I understand. – Nrc Jul 21 '17 at 17:06
1

One main reason to use "Vary: Accept-encoding" is as Oskar mentioned, to allow content to be delivered based on what the browser is capable of.

"Accept-encoding" is an especially important parameter for the "Vary" header as it allows proxies (middle-man servers) to properly understand that multiple compressed versions of your page can be cached in the proxies and therefore, your web page will be loaded fast for the new browsers that support compression, and uncompressed for older browsers that don't support compression.

This URL explains very well why vary is extremely important and even indicates you can save money as a result of using it:

https://www.fastly.com/blog/best-practices-using-vary-header/

  • You mean "shows for the tool that the site can load fast"? Might need to be clarified, or maybe it's just me. (At first I interpreted this as "shows the browser ...".) – Oskar Skog Jul 21 '17 at 15:53
  • I just edited it now. Man that was a tongue twister. lol – Mike Jul 21 '17 at 16:03
  • I updated my question. The explanation of the link you provide is way to complex for me! – Nrc Jul 21 '17 at 17:08
-3

Just check out the below Link, You will find the answer by yourself. https://stackoverflow.com/questions/16642190/how-to-specify-a-vary-accept-encoding-header

  • 2
    Link only answers are not high quality. It is much more useful to include the full answer here. You can even copy an answer from another StackExchange site with proper attribution. – Stephen Ostermiller Jul 21 '17 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.