37

I'm on a slightly flaky connection and I'm trying to improve my browsing experience with the use of a local proxy. According to my research, however, if I hit 'enter' in my browser on an existing URL, it'll send a Cache-Control: max-age=0 header to the proxy, which will, in turn, make round-trips to the server to revalidate the content.

I don't particularly want this; if the object is stale, the cache will re-fetch it, but if it's not stale I don't see why I'd want the object revalidated every freakin' time. If I suspect the page is old, I've got shift-F5 and I'm not afraid to use it.

So, is there a tunable somewhere behind the scenes in Chrome that'll turn this annoying behaviour off?

1
  • A workaround for hitting the same URL multiple times in a row and allowing the cache to work is to bookmark the page, then click the bookmark instead of using the refresh button or hitting Enter on the URL.
    – kevinpo
    Aug 31, 2021 at 20:08

5 Answers 5

31

I have found that if you browse to a page through your back-button or a link, Chrome doesn't send the max-age=0 header and will usually (if the apache server on the other side is configured for caching) use a cached version of the page.

However, when you enter the URL (e.g. www.example.com/abcd/index.html) directly into the address bar and then press Return, Chrome will always send the Cache-Control: max-age=0 header, which circumvents caching.

3
  • 8
    This is not an answer, it's a restatement of my question.
    – womble
    Feb 5, 2020 at 5:13
  • 2
    It appears that chrome does not set Cache-Control: max-age=0 if you load a new tab (vs. reloading the current tab). May 20, 2020 at 20:09
  • 1
    The "or a link" is the key here. If you are requesting the same URL multiple times in a row, Chrome apparently assumes that you don't just want the page to stay the same, so it doesn't use the cached version. If you go to a different page and then back (even by manually entering the original URL), it will allow the cached version to be used.
    – kevinpo
    Aug 30, 2021 at 19:52
6

It is possible to modify the headers Chrome sends to a webserver using either userscripts (ala greasemonkey) or extensions. Here is one extension that should work: ModHeader

According to the introduction and screenshot, adding a header such as cache-control max-age=1000 should be relatively straightforward. It also supports domain whitelists to prevent headers from being sent to specific websites. You may need enable certain experiments in chrome://flags for this work.

demo of adding headers

0

Browsers behave based on the response headers they receive. If the browser receives response headers like

Cache-Control: private
Expires: Thu, 01 Jan 1970 00:00:00 UTC

then, browser would always request with Cache-Control: max-age=0. This usually happens with Tomcat container, where the BaseAuthenticator adds these response headers when the variable disableProxyCaching is true. If you are facing similar issue, you can visit this link for solution.

Hope this helps to a certain extent :)

0

I'm trying to test caching on my website so need to simulate a 'new user', but of course Chrome sends Max-Age: 0 meaning the server's cache is bypassed so I can't test the server side caching.

What I found worked best for this use-case was in conjunction with Fiddler.

Chrome settings (must keep dev. console open)

enter image description here

and Fiddler:

enter image description here

This isn't good for the OP's issue - but I expect most people aren't currently finding this question due to the exact same problem.

2
  • Why would you introduce a separate proxy, when you could use an extension in the browser to achieve the same end result?
    – womble
    Feb 5, 2020 at 2:37
  • Because a lot of developers already have fiddler running and I like to minimize number of extensions running. It’s just another option. In my situation today I’m testing it then I’m done with it :) (I hope!)
    – Simon
    Feb 5, 2020 at 2:53
-1

Chrome adds Cache-control: max-age=0 header when you use self-signed certificate. Switching from HTTPS to HTTP will remove this header.

1
  • 1
    This is a terrible idea.
    – womble
    Jul 20, 2021 at 0:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .