How To Set Http Header Vary Value Correct To Make Cache Work Effective

My website use ezoic caching function to cache all my website pages. This can improve my website page access speed. Ezoic proxy server will create a copy of my website page and save those web page copy in their data center all over the world. So when client request a web page, and if the web page has been saved by ezoic cache before, ezoic will return the saved web page back to client instead of pass the request to the original web server. This way can improve web page response speed, save network bandwidth and reduce original web server resource cost.

1. What Dose Http Header Vary Means.

Above process is just the general process of cache proxy. But when a client request come to the cache proxy,  the returned cached web page is not only decided by the request url, it is also decided by a http header Vary‘s value.

The http header Vary‘s value is a serial of other http header’s name separated by comma (,). It is used as an extra condition for loading and return cached web pages. For example if the vary header value is  vary: Accept-Encoding,User-Agent. And when a client request web page to cache proxy, the cache proxy will return the cached 1.html web page only when the request client has same Accept-Encoding and User-Agent header value.

If another client ( which has different User-Agent header value ) request same web page to the cache proxy,  the proxy will load and return different User-Agent header value mapped cached web page to the client even if the web page url is same and have been cached before.

So the cache proxy will save same url web page content many times and matain mappings between request-url + http-header-value to web page content. For example, the client request http header User-Agent’s value can be Mozilla, Internet Explorer, Chrome, Safari etc. And suppose each user agent can has 5 sub versions, so there should be 20 copy of same url web page content are saved on the cache proxy server. This is very low efficiency and cost more rsources.

2. Bad Http Header Vary’s Value Example.

Now you should understand what dose http header vary means. And i will tell you what is the bad vary header’s value in below.

  1. vary: Accept-Encoding,User-Agent,Cookie : If you find your http response vary header’s value like this, then this is even bad than vary: Accept-Encoding,User-Agent, because each request client may has different Cookie, so this can make the cache very very very low efficiency. The cached web page is only used for the client request which has same Accept-Encoding, User-Agent and Cookie value. So do not include Cookie, User-Agent in the vary header value, if you find them then remove it. But some program like WordPress WP Super Cache plugin will add Cookie in the vary header by default for loggin user caching, we will tell you how to remove it in such cases in another article.
  2. vary: *: * is the worst vary header value. This can make the cache proxy stop functioning. Eevry request will be passed to the original web server. So do not use * in http header vary’s value.

2. Best Http Header Vary’s Value Example.

  1. vary: Accept-Encoding: We commonly use Accept-Encoding in the http header vary’s value. Accept-Encoding’s value will tell web server which content compression algorithm that client is using and can understand. Then web server will return that encoding compressed web page back to the client. If two or more client request use same accept-encoding, then same cached web page will be returned when they request same url page.
    http cache vary header


  1. How To View HTTP Headers, Cookies In Google Chrome, Firefox, Internet Explorer
0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x