5

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.

aleccentric
  • 101
  • 8
  • 2
    Can you show us examples of specific requests? You can [export network data](https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#export_requests_data) using Chrome Dev Tools. – Leonid Vasilev Mar 01 '17 at 11:46
  • Can you show us the request/response headers for the two requests (with and without the `X-Request-With` header)? – idbehold Mar 31 '17 at 20:19

2 Answers2

3

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.

aleccentric
  • 101
  • 8
1

It seems to be a bug in Chrome. When using the Vary header to compute its cache key, Chrome seems to perform a case-sensitive lookup, which doesn't work because it stores the headers in lowercase.

In your example, Chrome is looking for X-Requested-With. If you change the value of your Vary header for x-requested-with, it should work.

EDIT: I was actually mistaken. Maybe I lack sleep. It doesn't work either using lowercased header names. Sorry about that.