Reputation: 111
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.
Upvotes: 6
Views: 1062
Reputation: 91
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.
Upvotes: 1
Reputation: 111
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.
Upvotes: 3