Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome back button: only giving cached version of initial page, without any Ajaxed content

I have two pages, A and B. The flow is as follows:

  • Go to A
  • javascript Ajaxes a bunch of content to add to A, forming A'
  • go to B
  • pressing [Back] goes back to A, not A', without all the Ajaxed content

Has anyone else noticed this, and if so, how do you fix it?

If Chrome was caching the A' state just before going to B, and reproduces A' upon back, that would be acceptable. If Chrome simply re-loaded the entirety of A (including the Ajax requests that transformed it into A') that would work too. The current behaviour, which is loading an old, incomplete version of A, is not what I want.

EDIT: I know it's loading a cached version because the server isn't receiving any new requests when i hit [Back].

like image 911
Li Haoyi Avatar asked Apr 10 '12 21:04

Li Haoyi


1 Answers

This topic is old but thought I would share my solution. To get Firefox, Chrome and Safari to behave consistently, you have to set an unload handler on the page that needs to be reloaded when going back, and also use cache busting headers.

Example

In HTTP Headers

Cache-Control: must-revalidate, no-store, no-cache, private

And in the javascript for the page

$(window).unload(function(){}); // Does nothing but break the bfcache

Read here for more info: http://madhatted.com/2013/6/16/you-do-not-understand-browser-history

like image 108
Jayden Meyer Avatar answered Oct 14 '22 16:10

Jayden Meyer