I am having a frustrating problem with Firefox, so a call for help is in order. Basically, dynamic PHP pages randomly decide when they want to refresh. For example, let’s say we have a page, index.php, that displays all users. Then, a link on index.php goes to remove.php where a user is removed and the last line redirects back to index.php. When index.php loads back up, nothing has changed.

I’ve been searching for a long time, and I am getting nowhere. Here is what I have tried:

  • HTML meta tags to prevent page caching. Every single possible combination and none work.

  • PHP Headers to prevent page caching. Every single possible combination and none work.

  • I have read some problems where Apache 2 is not sending 200 OK. I have checked that, and the proper information is always being sent.

  • A reader of ours suggested that we should append a randomly generated number to the end of each URL. This seems to work, but there has to be a cleaner solution.

  • The setup works 100% in IE, Opera, and Safari. The problem only occurs in Firefox.

Any advice, links, or tips in the right direction are greatly appreciated. Hopefully, I am overlooking something painfully obvious.

HTML Form Builder
Ryan Campbell

Firefox Caching Issues by Ryan Campbell

This entry was posted 5 years ago and was filed under Notebooks.
Comments are currently closed.

· 28 Comments! ·

  1. Alex · 5 years ago

    Use ETag headers as an md5 of the page returned after it is generated by php (use ob_start and ob_get_contents etc), always either returning a different ETag along with the page content or a correct HTTP/1.0 304 Not Modified header to use the cached version. To always refresh (and never use the cache) just set the ETag header to a random value, e.g. with uuidgen used properly, or uniqid(rand(1111111,9999999)) or something like that. Might work for you! :-)

  2. Brad Wright · 5 years ago

    We use this code for any pages which must ALWAYS be fresh:

    Header( "Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" ); Header( "Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" ); Header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 Header( "Cache-Control: post-check=0, pre-check=0", FALSE ); Header( "Pragma: no-cache" ); // HTTP/1.0

    That pretty much guarantees every browser won’t cache the page. What was the combination you were using?

  3. Brad Wright · 5 years ago

    Hmmm… no white-space: pre on code blocks? Let me try again (sorry for spam):

    Header( “Last-Modified: ” . gmdate( “D, j M Y H:i:s” ) . ” GMT” ); Header( “Expires: ” . gmdate( “D, j M Y H:i:s”, time() ) . ” GMT” ); Header( “Cache-Control: no-store, no-cache, must-revalidate” ); // HTTP/1.1 Header( “Cache-Control: post-check=0, pre-check=0”, FALSE ); Header( “Pragma: no-cache” ); // HTTP/1.0

  4. JohnO · 5 years ago

    I’ve never had that problem, and I’m a long time PHP developer with Firefox. Usually a shift-refresh does it just fine. Are you sure there isn’t any proxy/firewall third-party software or hardware sitting between you and the server that would cache agressively?

  5. Jake · 5 years ago

    JohnO, if that were the case, wouldn’t it cache on IE equally as it does in FF?

  6. Ryan Campbell · 5 years ago

    Thanks for the feedback guys. Alex, I set the ETag to a random number, and had no luck with that. Brad, I used the Header you suggested and it still does it. JohnO, it is not something that only happens on my PC. It seems to be completely random.

    To see the problem recreated, go to our store and just click add item/remove item a bunch of times. Eventually, at seemingly random points, the page won’t refresh to show the results of what you clicked.

  7. Brett Epps · 5 years ago

    On Firefox 1.5 Beta 2, I’m getting this error when I try to remove something from my cart: “No input file specified.”

  8. Aapo Laitinen · 5 years ago

    Ryan, which version Firefox are you using? If you are using the beta, then this might be a bug in the new bfcache (back and forward cache). Using Firefox 1.0.7 on Mac I couldn’t reproduce the problem no matter how many times I tried (several dozen). How often should it happen?

    Anyway, if you haven’t already done so, disable all extensions and empty your cache. If that doesn’t help, install the LiveHTTPHeaders extension and see what gets sent to you. If there are no anomalies, a fresh install of Firefox and using a packet logger (such as Ethereal) to capture exactly what’s happening would probably give the necessary detail to file a bug with a chance of being fixed.

    Jake, Firefox doesn’t use the system settings for proxies (though I think it imports them during the install). It is possible to have a proxy-related problem with just one of the browsers.

  9. Zach · 5 years ago

    What about the server’s time being set too far in the future, and when Firefox requests the page, its getting a “Not Modified” response back? FF would then used the cached page.

    I’ve seen odd behavior with date syncing problems like that in the past. Just a thought.

  10. Ryan Campbell · 5 years ago

    Just an update - Aapo may be on to the solution. I have tried disabling different extensions, and it appears the web developer toolbar may have something to do with it. I’ll do some more testing and get back to everyone.

    Thanks a ton for all of the advice.

  11. Humberto Roa · 5 years ago

    I have the same issue. Disabing web developer toolbar seems to fix it.

  12. Tom Keels · 5 years ago

    I have the same issues using jsp pages. Firefox (at random) uses the cached pages even thought I have the ALL the no-cache options I can think of in the headers.

    I do not nor have I ever had the web developer toolbar instatlled on my machine. IE works just as expected refreshing the page every time, but firefox and Opera both seem to cache the page regardless of the no cache statements in the headers.

    But what’s funny is that it was working in firefox last Friday when I left work, came in to work on Monday and tried it again and stopped working again.

  13. Jeremy · 5 years ago

    I’m having a similar problem. I have a flash page that needs to read constantly updating XML files. It works fine in IE, but not in Firefox (a non-beta version). And emptying my cache isn’t an option since this site is access by lots of other people, not just myself. Since it’s caching an indirectly accessed XML, I really don’t know how to solve this. I’m thinking I’ll unfortunately have to tell Firefox users to use IE for this.

  14. Working Nomad · 4 years ago

    I am having the same issue with Portable Firefox and it is driving me nuts!

    I have set the cache to 0mb and I am still being served cached pages!

  15. bone · 4 years ago

    Same problems here. I discovered, however, that any query string (GET variables) seemed to stop the caching problem even when the query string doesn’t change and the page is refreshed.

  16. Rob · 4 years ago

    Jus put a windows.onload event handler then firefox wont cache.

    http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching

  17. Rob · 4 years ago

    Sorry, for my previous post, i mean windows.onunload event handler.

  18. Olly · 4 years ago

    GAAAH! I’m slowly going insane!

    I’ve got a page where the user clicks something in a collapsable tree-view and they’re taken to another page. I’ve set up a script that restores the page to the way it was when they left it if they click “back”.

    The problem? Firefox is caching the page, so the session variable that I pass back isn’t there unless I click “reload”. None of the tips from the Firefox cache page in the last comment work, only disabling the cache from the web-dev toolbar does the trick.

    But on other machines around the office, the page works perfectly in Firefox. GAAAAAHHHHHHH!!!!

    Oddly, it’s also firing onload when I hit ‘back’ - which contradicts all sorts of resources around the interweb. Bizarroweird.

  19. Rinke · 4 years ago

    Ever since I got into this business I’m having trouble with caching. Fixing it by adding a random number to the query string has always been a nice solution for me… until now

    It seems logical that whenever a developer passes different variables to a webpage, the content is bound to be different and the cache should not be used.

    However, as bone mentioned, firefox does not use the cache even when the exact same variables are sent. This undermines a nice system to control caching but hey, if this was a perfect world I wouldn’t have anything to do ;-)

  20. koevoets · 4 years ago

    I had the same issue too. Disabeling the web developer toolbar fixed it.

    Even after installing a new version of the web developer toolbar i didn’t have the problem anymore, so maybe its only caused by an older version..

  21. anri · 4 years ago

    thx for that solution koevoets, simple and easy.

    greetz andrea

  22. Albert · 4 years ago

    I have just the opposite problem.

    I have a bunch of images which are generated automatically once a week for stats etc. These are all generated from one PHP script - showGraph.php?id=1 or showGraph.php?id=7729.

    So I open Firefox and browse around on the site and go to other sites and come back and Firefox keeps using the cached version. Then I close Firefox and starts it up again. At this point instead of using the cached version, Firefox downloads the image from the server again - even though the cached version should have been used.

    The headers are set as follows:

    header(“Expires: Sat, 7 Oct 2006, 23:59:59 GMT”); header(“Cache-Control: public”); header(“Last-Modified: Sun, 1 Oct 2006 00:00:00 GMT”); header(“Content-type: image/png”);

    Is there something I’m missing or should be doing to have Firefox use the cached copy instead of downloading an updated version after I close Firefox completely and start it up again.

    I’m using FireFox 1.5.0.7 on Windows XP. Had the same issue since FireFox 1.5.0.1.

    TIA

    Albert

  23. Brent · 4 years ago

    I am having this caching issue with Flash, but only in Firefox. Safari loads my updated .swf correctly, but Firefox does not.

    Like someone else mentioned, this problem is completely random. I went through this with Firefox for several months last year, then had no problems for the last 3-4 months. Now it’s popping back up again.

  24. John · 4 years ago

    Solution: Change the URL to be different each call

    imagePlacement.src= ‘getimage.php?id=100&postNotUsed=’+Date();

  25. Joe Taro · 4 years ago

    I had a problem with web developer as well, only it was causing firefox to NOT cache things. Having it reload unchanged images each page visit was highly annoying.

  26. WildChild · 4 years ago

    I wonder if this is still happening with Firefox and MSIE ; the caching of Flash applets together with the data ; which is annoying as freak if you want to protect the data and how to prevent that? Embedding them together does not work because both the container and the contents get cached; msie doesn’t even want to abide the no-caching rules by caching in a hidden directory.

    I think your problem might be very similar?

  27. Shawn · 4 years ago

    Nice…thanks.