P
P
Pavel Karinin2017-08-07 14:28:05
Web development
Pavel Karinin, 2017-08-07 14:28:05

Why does Chrome give the local cache on back and forward navigation (with buttons) ignoring Cache-Control headers with values: must-revalidate, no-cache?

Maybe I'm doing something wrong or I don't understand something... but the situation is as follows: a web application (ASP.NET) running on a server (IIS 10) creates dependencies (CacheDependency) for certain pages, when they change, it connects to Dependency resource (page) ceases to be relevant, returns to the client a fresh version with headers:

Cache-Control: private, no-cache, must-revalidate, max-age=0
Last-Modified: Sun, 06 Aug 2017 18:03:49 GMT

... and this works well and correctly in all browsers, but only until the client hits the Back/Forward navigation buttons, in which case the browser returns the from disk cache. For clarity, I will demonstrate the headings for three situations.
1. The first call to the server for a resource:
REQUEST
GET [url] HTTP/1.1
Host: [host]
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
DNT: 1
Referer: [refer]
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4

RESPONSE
HTTP/1.1 200 OK
Cache-Control: private, no-cache, must-revalidate, max-age=0
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Last-Modified: Sun, 06 Aug 2017 18:03:49 GMT
X-XSS-Protection: 1; mode=block
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
Date: Mon, 07 Aug 2017 10:52:00 GMT
Content-Length: 3323

2. Re-requesting the resource (provided that the requested resource on the server has not changed)
REQUEST
GET [url] HTTP/1.1
Host: [host]
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Accept: text/css,*/*;q=0.1
DNT: 1
Referer: [referer]
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
If-Modified-Since: Sun, 06 Aug 2017 18:03:49 GMT

RESPONSE
HTTP/1.1 304 Not Modified
Cache-Control: private, no-cache, must-revalidate, max-age=0
Accept-Ranges: bytes
Last-Modified: Sun, 06 Aug 2017 18:03:49 GMT
Date: Mon, 07 Aug 2017 10:53:00 GMT

3. Resource request after navigating through the Back button: the resource on the server has changed or has not changed, it doesn’t matter anymore, since the browser does not send the request, but uses its own cache, issuing such a response
Request URL:[url]
Request Method:GET
Status Code:200 OK (from disk cache)

to this alleged request
! Provisional headers are shown
Referer:[referer]
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36

I can’t understand what’s the matter, help me figure it out, it is necessary to achieve that, regardless of what action (through buttons or via a link, direct entry of the address into the address bar, etc.), the browser would check with the headers returned by the server and only after accepting solution: issue the resource from your own cache (if you know that it is still up-to-date on the server) or download the latest version after learning that it appeared on the server, i.e. own (browser) copy is no longer up to date. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question