by
KK » Sat Oct 13, 2012 7:24 pm
@cheesypoof
HTML is always changing to reflect new content, so in most circumstances it is not static. Browsers therefore will not cache it by default as they don't want to risk serving stale content.
I agree this is how browsers are supposed to behave (and most of the time they do behave like this) however a very recent happening served to shake my belief in this axiom.
I was contacted by a client with a problem that I had never encountered before - any time he made any changes to the pages in the admin-panel, he had to use F5 to refresh for the changes
to appear in the admin-panel!Create a new dynamic-folder and the folder won't appear in the list until F5 was hit. Add images to portfolio and the same thing there. It was really a frustrating experience.
The intriguing thing was that *all* the browsers on his machine were displaying the same problem (he send me a video clip) while when I accessed the admin-panel from my machine everything seemed ok.
Clearly (for reasons still not understood by me - maybe there was a proxy somewhere in the chain) the browsers on his machine were caching HTML too aggressively - to the extent that they never requested the web server for any page that had been accessed before.
I rectified the problem by making the web-server explicitly send instructions to the browsers absolutely not to cache at all (not even once) any of the admin-panel pages.
This is how I did it (might come useful to someone) -
Edit the 'couch/config.php' file and add the following lines at the very end of it
- Code: Select all
if( defined('K_ADMIN') ){
// HTTP headers for no cache
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
I am not sure if it'd be a good idea but if necessary the same instructions could be given for the normal front-end pages too (by removing the 'if' condition). The client will never have to hit F5 again as the browser will always request the web server for all pages. The caching part could be handled completely by the server alone.