Use visibilitychange event instead of unload event to improve performance and avoid a bug#715
Open
Flimm wants to merge 2 commits into
Open
Use visibilitychange event instead of unload event to improve performance and avoid a bug#715Flimm wants to merge 2 commits into
Flimm wants to merge 2 commits into
Conversation
The "unload" event has these drawbacks: - It breaks the browser's back/forward cache (bfcache), worsening the performance of the browser when pressing the back button or forward button - It may be disabled entirely be the website's Permissions-Policy It is preferable to use the "visibilitychange" or "pagehide" events instead. These events have been supported across browsers since April 2021 and July 2015, respectively. `document.hidden` has been supported across browsers since July 2015. See: https://web.dev/articles/bfcache#optimize https://developer.mozilla.org/en-US/docs/Glossary/bfcache
Owner
|
I agree about avoiding the |
The "unload" event has these drawbacks: - It breaks the browser's back/forward cache (bfcache), worsening the performance of the browser when pressing the back button or forward button - It may be disabled entirely be the website's Permissions-Policy It is preferable to use the "pagehide" events instead. This event has been supported across browsers since July 2015. See: https://web.dev/articles/bfcache#optimize https://developer.mozilla.org/en-US/docs/Glossary/bfcache
Author
|
I misread MDN documentation, d'oh! I feel a bit stupid now. It's better to use the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The "unload" event has these drawbacks:
Permissions-PolicyIt is preferable to use the "visibilitychange" or "pagehide" events instead. These events have been supported across browsers since April 2021 and July 2015, respectively.
document.hiddenhas been supported across browsers since July 2015. This pull request makes the required change.See:
https://web.dev/articles/bfcache#optimize
https://developer.mozilla.org/en-US/docs/Glossary/bfcache