In a 2007 post titled “ Mastering the Back Button Using Javascript, ” a guy named Patrick Hunlock argued that simply including the onbeforeunload handler in the page would stop caching. (I think browser caching.) It was very strongly configured:
It’s easy to have an unbeforeunload event handler - whether it really does something, whether you create a dialog box or not, even if the full function declaration consists entirely of {} - just defining the event handler will prevent caching pages.
In fact, even if you enable page caching, the page will not be cached. The presence of an onbeforeunload event means that the page will be reconstructed every time it is accessed. Javascripts will be restarted, server scripts will be restarted, the page will be built as if the user hit it the first time, even if the user got to the page by simply clicking the "Back" or "Forward" button.
It's funny that I can’t find a mention of this anywhere except for one or two people who allude to Mr. Hunlock’s post. Can anyone clarify this issue? Is this true, or can I use this event safely?
source
share