title: HTML5 History API back button with partial page loads
body: <p>To improve the performance/responsiveness of my website I have implemented a partial page load using AJAX, replaceState, pushState, and a popstate listener.</p>
  
  <p>I essentially store the central part of my page (HTML) as my state object in the history. When a link is clicked I request just the central bit of the page from the server (identifying these requests with a different Accept header) and replace it with javascript. On popstate I grab the previous central part and push it back into the dom.</p>
  
  <p>This mostly works fine, however I have found a particular issue which I am stuck on. It is a little complicated to explain, so my apologies if this isn't very clear.</p>
  
  <p>There is a search form on most of our pages. The partial page loading via ajax is only on GET requests, and the form performs a POST which results in a full page load.</p>
  
  <p>If I navigate the following set of pages, I end up on a malformed partial page consisting of <strong>ONLY</strong> the central content, without any of the surrounding dom:</p>
  
  <p>Start on the Home Page (via full page load) - perform a Search (post-redirect-get)<br>
  Takes you to Search Results (via full page load) - then click Home<br>
  Returns you to the Home Page (via dynamic get) - click browser back<br>
  Search Results (from popstate listener) - click browser back<br>
  Malformed home page.</p>
  
  <p>When the malformed home page appears, my popstate listener is not present at all.</p>
  
  <p>What I <em>think</em> is happening, is that the second load (dynamic, partial) of the home page is being cached by the browser, and then when the full page back occurs, the browser is merely showing the cached partial response rather than the full page.</p>
  
  <p>To try to remedy this I have added a Vary: Accept header to the response to let the browsers know that content may change based on the accept header. I have also added Cache-Control max-age=0, pragma no-cache, and a past expiry date to the partial loaded content to try to force the browser not to cache this, but none of this solves it.</p>
  
  <p>Unfortunately my company does not allow external traffic to our dev servers, so I cannot show you the problem. I have looked at various similar questions on here, but none of them seem quite the same, nor do the solutions suggested seem to work.</p>
  
  <p>If I add a pointless parameter (blah=blah) to my dynamic GET requests, this solves the problem. However this is an ugly hack that I'd rather not do. This seems like it should be solvable with headers, since I think it is a caching problem. Can anyone explain what's going on?</p>