title: JavaScript to reload page if it is in bfcache
body: <p>I'm trying to put together a script for the browser to decide if the page it is loading comes from bfcache or from the server.  I'm 99% sure bfcache is the issue, because all the other problems I've seen of this nature cite bfcache as the issue.</p>
  
  <p>This is relevant because the bfcache page "freezes" the state of the JavaScript on a website I'm working on (I didn't write those scripts, I'm a JavaScript amateur), and if you use the back button to get back to the page, the scripts don't work.  They work fine, though, if you hit the refresh button.</p>
  
  <p>This is my attempt at solving this issue:</p>
  
  <pre><code>&lt;body onload="noBFC()" onpageshow="checkCache()"&gt;
  // Lots of HTML content
  
  &lt;script type="text/javascript"&gt;
      function checkCache(){
          if (cached == true){
              location.reload(true);}
      };
  
      var cached = "";
  
      function noBFC(){
          cacheCheck = false;
      };
  
      window.onunload() {
          cacheCheck = true;
      };
  &lt;/script&gt;
  </code></pre>
  
  <p>The rationale being, whenever the user navigates away from the page, <code>window.onunload()</code> will set the variable <code>cached</code> to boolean "true", to indicate that it has been cached by bfcache.  </p>
  
  <p>Then, whenever the page is shown again with <code>onpageshow</code>, the script checks that variable.  If it's "true", it forces a page reload with the value of <code>cached</code> set to "false".</p>
  
  <p>Is there something easy I missed syntactically, or is this just not a workable solution?</p>