3 ms·
Deprecating the `Unload` Event
- paulddraper 3y ago1. Does the WhatWG standard matter anymore? 2. No mention of beforeunload. I imagine that is still good?
- lioeters 3y agoAccording to the Chrome Developers page on the Page Lifecycle API [1], and the MDN page [2], it seems `beforeunload` is still OK to use. https://developer.chrome.com/blog/page-lifecycle-api/#event-beforeunload https://developer.chrome.com/blog/page-lifecycle-api/#event-... https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#usage_notes 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.
- yMMe2WYE_D 3y ago> should be used only minimally Like that will ever happen. I just got such warning while leaving https://news.ycombinator.com/item?id=37086041 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.
- matthews2 3y agoWhatWG is more like documentation of what browsers are currently doing, rather than a standard
- paulddraper 3y agoOkay so this is an announcement WhatWG will change :)
- lapcat 3y agoNote that Safari deprecated "unload" a long time ago: https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html https://developer.apple.com/library/archive/documentation/Ap...