google-chromehttp-headersxmlhttprequestbrowser-cachevary

Does Chrome support the HTTP Vary header


Does Chrome's cache support the HTTP Vary header? For a specific url request the server responds two different html files depending if it's an ajax request or not. So I added the Vary header to X-Requested-With. I was expecting Chrome to record two cache entries, but it doesn't seem to be the case. I always get a cache hit of the first request I made. Is this the normal behavior?

Thanks.


Solution

  • For the record. I have not been able to use the HTTP Vary header with X-Requested-With in Chrome. Chrome didn't consider the HTTP Vary header when caching. So the cache hit returned always the same content.

    As a workaround I added a question string (like ?ajax=1) only when doing the request with ajax.

    Ex: http://localhost/myrequest.php http://localhost/myrequest.php?ajax=1

    This way Chrome stored two cache entries, one with ajax and one without.