3

Firefox seems to save the whole page state including values of javascript variables and DOM and restoring it when user hits back button. How to prevent this behaviour?

Cache on server side prevented:

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-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0");
header("Pragma: no-cache");

All forms on page have autocomplete='off', all hidden input elements have it too. onload event is not fired.

Is there any way to tell Firefox totally forget page state after form submission? setting timeout in onsbumit handler which will force page reload is a bad idea, because next page can react in unpredictable time. In case of long response reload will break the request.

How to reproduce:

<body>
  <form method='POST' action='http://httpbin.org/post' autocomplete='off'>
    <input type='text' placeholder='Enter something' name='data'  autocomplete='off'/>
    <input type='hidden' name='token' value='and_token_field_that_must_not_be_cached' autocomplete='off'/>
    <input type='submit' />
  </form>
  <span id='counter'></span>
  <script>
    var tick = 0;
    setInterval(function () {
      document.getElementById('counter').innerHTML = tick ++;
    }, 300);
  </script>
</body>

Wait a bit, press submit, then back. FF will display the same counter value as before page submission, Chrome will reset it.

  • 1
    Might be worth checking out http://stackoverflow.com/questions/9918481/stop-javascript-and-html-from-loading-from-cache – Peter Berg Jun 20 '13 at 13:18
  • 1
    Your page is being cached by Firefox back-forward cache. Here is a recipe: http://stackoverflow.com/questions/1195440/ajax-back-button-and-dom-updates/1195934#1195934 – Mikhail Jun 20 '13 at 14:40
  • Thanks, looks like that's it. I'll investigate this closer. – user2504747 Jun 20 '13 at 14:50

0 Answers0