Why doesn't Safari honor my cache-control dire

2019-02-16 21:17发布

问题:

There is a particular page that I would like the browser to always load, particularly when the user presses the browser back button to get to it.

So I use the following 'Cache-Control' directive in the header for this page (taking the PHP directly from my code).

$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';

This works for FF, IE and Chrome, but Safari (5.0.1) seems to ignore the directive and fails to reload the page (across multiple users, so it doesn't seem to be a setup specific problem). Searching hasn't revealed any known bugs, so I'm assuming there is something amiss on my end.

Any pointers would be much appreciated.

Update: just found this answer on SO.

Safari browser ignoring my no-cache

Haven't tried it yet, but looks promising. Very strange that it is an addition to the body tag, so Im skeptical.

回答1:

The answer is to include the following attribute in the body tag to force Safari to reload the page:

onunload=""

As in:

<body onunload="">

I found this here: Safari browser ignoring my no-cache

Which in turn got it from this thread: Is there a cross-browser onload event when clicking the back button?



回答2:

Also see this Webkit bug report: https://bugs.webkit.org/show_bug.cgi?id=71509

I am experiencing the same issue, and it appears to be to be a bug in Safari.