javascript-tutorial / javascript-tutorial/en.javascript.info

recommend against using `unload` event

Open
#3,469 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
25.5k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

Currently this article recommends using the unload event to close popups and send stats. unload cannot be relied upon and best practice is to avoid it entirely, using pagehide or visibilitychange.

E.g. popups should be closed in pagehide, not unload because a page that canenter BFCache will not fire unload but will fire pagehide

Stats should not be sent from unload because if the page goes into BFCache and the user never returns, the unload event will never fire.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open 2-ui/5-loading/01-onload-ondomcontentloaded/article.md and review the window.onunload section linked in the issue. Update the recommendation so popup cleanup and statistics guidance no longer relies on unload, and ensure the finished article reflects pagehide or visibilitychange and the BFCache limitation described here.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.