2011-04-08

Force page refresh on back button

I've tried to force a page to be downloaded again by browser when user clicks back button, but nothing worked. I appears that modern browsers have separate cache for pages, which stores complete state of a page (including JavaScript generated DOM elements), so when users presses back button, previous page is shown instantly in state the user has left it. If you want to force browser to reload page on back button, add onunload="" to your (X)HTML body element:

<body onunload="">

This disables special cache and forces page reload when user presses back button. Think twice before you use it. Fact of needing such solution is a hint your site navigation concept is flawed.



2012-04-13 10:03:02
tomek
maybe try to set headers disabling cache, if you have access to the server side, thus a page loaded for the first time won't be cashed by the browser, you can ggogle for appropriate header setting
2012-06-07 08:13:09
KiddoKenshin
Bro, you saved my day.
Note that 'unload' does not work, but 'onunload' works for me.
(on FireFox13)
2013-01-21 11:43:26
Jakub Fedyczak
tomek: it's a different animal. Browsers ignore any headers in some cases.

KiddoKenshin: updated - thank's for the tip.
2013-02-12 11:08:42
Chris
thanks, that helps me a lot...
2013-06-11 00:42:49
Giovanni Ferrari
woooow thank you so much

This is exactly what we needed, I had been looking for a solution to my problem for hours.

Thanks!
2014-05-27 11:02:08
sergey gorbikov
thanks, bro
you really helped me
i spent 15 min in the web w/o success, but now it all works
Add comment...