I’m tying to understand some odd browser behavior that I have noticed. I have a number of pages which (for the sake of experimentation) I serve up with headers which I think should cause the page to be cached:
Cache-Control:max-age=3600
Content-Length:66
Content-Type:text/html
Date:Thu, 06 Dec 2012 13:08:01 GMT
Expires:Fri, 07 Dec 2012 14:19:41 GMT
Server:Apache-Coyote/1.1
As expected, when I navigate to one of these pages via a link on one of the other pages then the browser serves the page straight out of its cache and there is no call to the server. However, when I reload one of these pages by pressing the browser Refresh button, the cache-related headers seem to be ignored and a request gets sent to the server.
I have seen this behavior on the latest versions of Chrome and Firefox and in IE9.
Does the HTTP standard mandate this ‘special treatment’ of requests initiated by a user refresh (and if so what is the purpose of the ‘Hard Reload (Ctrl+Shitf+F5)’ in Google Chrome), or is there some other explanation?
Normally when you request a page, the browser “should” send a HEAD request to the server asking for (only) the headers of the document you requested. If you only set above headers during a POST or GET request, it would explain why the browser will think of the document as expired and refetch it.
But, looking at it from another perspective, since the primary reason to use the refresh functionality would be to “refresh” the page, it would make sense that browsers don’t serve a cached copy but do what you ask = get the latest version, because why else hit refresh?
I can confirm though that some browsers (for example chrome) will not update all resources (like linked .js files) during a refresh, but they will update the page you refreshed!