Reputation: 73112
I've got an image on S3, that has a Cache-Control
header set to public, max-age=3600
. So, downstream systems (proxy, browser, etc) should cache it for 1 hour.
I can see the browser returns 304 (not modified) after subsequent requests.
I've then gone and updated that image on S3 (the resource isn't versioned..the URL hasn't changed, just the _content), but the browser went and got the new version. (e.g HTTP 200).
Here's the chrome network traffic:
Requests:
~ image changed behind the scenes ~
How is this possible? Am i not setting the correct header?
Two things are confusing me:
max-age
hasn't been reached?My guess is - i'm not setting the right cache-control header or something. So can someone please shed some light on this behaviour, and let me know what i need to do to cache resources for 1 hour :)
Thanks!
Upvotes: 4
Views: 1411
Reputation: 254916
There is ETag
specified in the response.
The ETag
is explained as such in the spec
An entity-tag can be more reliable for validation than a modification date in situations where it is inconvenient to store modification
dates, where the one-second resolution of HTTP date values is not
sufficient, or where modification dates are not consistently
maintained.
so browsers prefer it over the date-based expiration.
Hence, your browser makes a request every time, and unless the content has changed - http 304 is returned. Otherwise - it's http 200.
If you only want time-based expiration - remove ETag
.
References:
Upvotes: 3