Both sites emphasize that it should be used only minimally, to attach and remove an event listener as needed, i.e., when there are unsaved changes.
---
> ..On Firefox, the beforeunload event is not compatible with the back/forward cache (bfcache): that is, Firefox will not place pages in the bfcache if they have `beforeunload` listeners, and this is bad for performance.
> However, unlike the `unload` event, there is a legitimate use case for the `beforeunload` event: the scenario where the user has entered unsaved data that will be lost if the page is unloaded.
> It is recommended that developers listen for `beforeunload` only in this scenario, and only when they actually have unsaved changes, so as to minimize the effect on performance.
Like that will ever happen. I just got such warning while leaving https://news.ycombinator.com/item?id=37086041 , probably some ad on Forbes site used it.
It is like with right mouse click menu - the only sites that really need to replace it is Google Docs or equivalent, yet there are thousands of sites that restrict it for "security" or some other crazy reason.
6 comments
[ 3.6 ms ] story [ 21.9 ms ] thread2. No mention of beforeunload. I imagine that is still good?
https://developer.chrome.com/blog/page-lifecycle-api/#event-...
https://developer.mozilla.org/en-US/docs/Web/API/Window/befo...
Both sites emphasize that it should be used only minimally, to attach and remove an event listener as needed, i.e., when there are unsaved changes.
---
> ..On Firefox, the beforeunload event is not compatible with the back/forward cache (bfcache): that is, Firefox will not place pages in the bfcache if they have `beforeunload` listeners, and this is bad for performance.
> However, unlike the `unload` event, there is a legitimate use case for the `beforeunload` event: the scenario where the user has entered unsaved data that will be lost if the page is unloaded.
> It is recommended that developers listen for `beforeunload` only in this scenario, and only when they actually have unsaved changes, so as to minimize the effect on performance.
Like that will ever happen. I just got such warning while leaving https://news.ycombinator.com/item?id=37086041 , probably some ad on Forbes site used it. It is like with right mouse click menu - the only sites that really need to replace it is Google Docs or equivalent, yet there are thousands of sites that restrict it for "security" or some other crazy reason.