Does Chrome support the HTTP Vary header
Asked Answered
S

2

6

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.

Seeley answered 1/3, 2017 at 3:16 Comment(2)
Can you show us examples of specific requests? You can export network data using Chrome Dev Tools.Decelerate
Can you show us the request/response headers for the two requests (with and without the X-Request-With header)?Schwann
S
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.

Seeley answered 31/3, 2017 at 10:54 Comment(0)
A
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.

Aemia answered 22/8, 2018 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.