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
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
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
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.

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
2014-12-23 18:00:47
verdiğiniz çözüme kakam
2015-02-11 13:34:08
Finally! This works like a charm! Thanks
2015-03-23 01:52:11
Doesn't work on iphone :( Any suggestions
Add comment...