5

I'm implementing caching at the server application level, because my hosting doesn't provide Apache caching modules and it's not possible to use a reverse proxy there. Its cheap and fast hosting, so I don't want to change it.

Can I detect when the user presses F5 or Ctrl+F5, instead clicking on link to one page? I'm quite sure there are some special HTTP headers generated on request like this. Without it, the page will be always served from cache.

1
  • I would expect an If-None-Match header if the response to the first load did contain an ETag header.
    – Bergi
    Commented Nov 16, 2019 at 19:04

2 Answers 2

3

No. The browser will send the same information on a refresh as if the user had just come to that page, with the same referrer information. Hence the problem of double-POSTing if someone refreshes the destination page for a form.

What you could do is have a refresh button on the page (as Google Ads used to have before they removed it), which you could use to send a relevant GET or POST variable to the server which would trigger the update you were looking for.

Alternatively, you could use a cookie to determine if the user had seen that page was the last page that user had seen as treat a second request for that page as a refresh.

1
  • I think you are wrong, cause find some(outdated) information on stackoverflow, will post it now.
    – LeonidMew
    Commented Nov 17, 2019 at 5:58
3

Browsers do send additional headers, but behavior different. This info in link a bit outdated: stackoverflow question

Looks like Cache-control:no-cache is the best solution, to check for Ctrl+F5, but better to check not the only one header.

Just checked on Firefox Ubuntu, F5 gives nothing, but Ctrl+F5 request contain this

Pragma  no-cache
Cache-Control   no-cache

Checked Chromium - same behavior, same two headers.

This headers may pass any proxy in the middle, and come to end - site server, as I known.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.