How can I detect when the client hits F5 / refresh? Are there any headers sent to the server to indicate this that I can grab? I'm doing some server-side caching and I'd like to automatically expire the cache when a refresh is detected. Thanks.
Detect when the browser hits "refresh" in Python's BaseHTTPServer
481 Views Asked by ensnare At
2
There are 2 best solutions below
0
On
I'd look at ETags and conditional cache validation requests.
If the browser sends a If-None-Match header they had a cached copy and want to see if they can reuse it. Instead of sending a 304 Not Modified you instead clear your cache, produce a full 200 OK response and set a new ETag header.
ETags may be a more correct solution, but simply looking for the
Cache-Controlheader is enough, since the browser will use it to indicate caches should not be used.Chrome sends
Cache-Control: max-age=0, but some other browsers sendCache-Control: no-cache. You may want to expire cache on any cache control header you don't recognize.Or even: