View Full Version : Forcing a Cache Refresh

01-06-2011, 04:02 PM
We're having a big issue with our site. We use .htaccess to specify mod headers and expires in order to stipulate caching of various file types. Most of these are fairly long expire times (i.e. several months).

However in the past week we made some big changes to the site -- primarily to the underlying javascript that controls many of the site's functions.

New visitors to the site have no problem -- and the new code works fine.

However, if you've visited previously, because of the old htaccess, your browser will keep pulling up the cached version of pages, scripts, etc., and you will keep encountering errors -- or the site simply won't behave properly. Of course, if you thought to refresh your browser (i.e. reload any page on the site), the new javascript external file would be loaded and the site would begin working perfectly.

But we've found that many visitors don't think to reload the page -- and so we've had complaints that the site isn't working.

Clearly, the solution is to force a cache refresh. But so far, every attempt we've made to do this has failed.

We tried adding new "must-revalidate" commands to the header.php file (it's a dynamic site), but that didn't stop the number of complaints from users reporting problems with the site. We also tried adding a javascript error handler to header.php that would force a reload of the page if an error was thrown. But although this should work -- because return visitors are seeing the cached page, and not this new addition to the code -- the command falls on deaf ears.

At the same time, we got rid of our old cache control code from htaccess and replaced it with new code that we thought would force everyone's browser to use the fresh pages and not the cached versions, but that also hasn't worked. Here's what we currently have at the top of htaccess:

<IfModule mod_headers.c>
Header set Cache-Control "private, must-revalidate"
Header unset Expires
Header unset Last-Modified
FileETag None
Header unset Pragma

We'd appreciate any and all help for what we could add either to htaccess or to header.php in order to ensure that everyone is accessing the new versions of all html, php, js, css file types. (Notice we didn't even use FileMatch in the above code, as we were trying to force everything to be fresh.)