Bite code
Bite code

Reputation: 596703

Why is Chrome still caching this request?

I have a page with all the cache control goodies set, and yet, Google Chrome keeps pulling it from the cache. We emptied all navigation history but after one reload, Chrome caches it again :

Request URL:http://stuf.com/path/to/foo
Request Method:GET
Status Code:200 OK (from cache)
Response Headers
Accept-Ranges:bytes
Age:0
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Encoding:gzip
Content-Language:fr
Content-Length:7289
Content-Type:text/html; charset=utf-8
Date:Fri, 17 Jul 2015 23:19:54 GMT
Expires:Fri, 01 Jan 2010 00:00:00 GMT
Server:nginx
Vary:Accept-Language, Cookie, Accept-Encoding
Via:1.1 varnish
X-Varnish:1867509088
X-Varnish-Cache:MISS
Request Headers
Provisional headers are shown
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36

We do have varnish setup, but as you can see from X-Varnish-Cache, it's a miss. Plus, the status code section does state that Chrome is using the cache.

Upvotes: 4

Views: 3310

Answers (1)

DivineTraube
DivineTraube

Reputation: 731

In your response header, Chrome states that the age is 0, i.e. the response has been cached for a second or less.

It should probably work if you wait for more than a second or include a cache validator: an ETag or a Last-Modified header which allows the browser to trigger a revalidation (conditional request) instead of a normal GET request.

The problem is likely the must-revalidate (which you do not need with max-age=0):

When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server

Without and ETag or Last-Modified header a revalidation is not possible.

Also, you can skip the Expires header:

If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive. This rule allows an origin server to provide, for a given response, a longer expiration time to an HTTP/1.1 (or later) cache than to an HTTP/1.0 cache.

from the RFC.

Upvotes: 2

Related Questions