You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The unload event is used to unsubscribe the connection.
Chrome lighthouse audit say the unload event is a bad practice and prevent Back/forward cache
A browser optimization that enables instant back and forward navigation. It significantly improves the browsing experience for users—especially those with slower networks or devices.
Would it not be better to unsubscribe on beforenuload event instead?
beforenuload still prevent back/forward cache on Firefox, but not on Chrome.
I don't know if there would be any other implications.
The text was updated successfully, but these errors were encountered:
The unload event will be gradually deprecated starting from Chrome 117. The deprecation will occur by gradually changing the default so that unload handlers stop firing on pages unless a page explicitly opts in to re-enable them.
SuperPat45
changed the title
Unsubscribe on beforeunload instead on unload fore Back/forward cache compatibility
Unsubscribe on beforeunload instead on unload has Chrome will stop firing unload events
Aug 19, 2023
Note that beforenuload may in some cases be fired even if the user doesn't end up leaving the page.
One such case if when you click a link that leads to downloading a file (but the link doesn't have a download attribute). In that case, the browser will fire beforenuload when the link is clicked based on the assumption that the link will lead to a new page. Then when the browser receives the response and sees that it has a Content-Disposition: attachment header, it realizes that the page will not be unloaded after all and then it will just keep it running even though beforenuload has already been fired. (Or that's at least how it worked 5 years ago when I last tested it.)
The unload event is used to unsubscribe the connection.
Chrome lighthouse audit say the unload event is a bad practice and prevent Back/forward cache
Would it not be better to unsubscribe on beforenuload event instead?
beforenuload still prevent back/forward cache on Firefox, but not on Chrome.
I don't know if there would be any other implications.
The text was updated successfully, but these errors were encountered: