Skip to content

Proposal: Disallow running unload handlers #39

Description

@rakina

If a document specifies Document-Policy: unload=?0, the unload event will not be dispatched for that document.

This is useful because the existence of an unload handler in a page will make it be not eligible for BFCache on some browsers (e.g. Desktop Chrome and Desktop Firefox), impacting its performance. With this header, the page can guarantee that the unload handler won't be a problem for BFCache.
(Note that a page will need to ensure its iframes won't run unload handlers too if it wants to be BFCacheable, which it can do through setting Require-Document-Policy: unload=?0)

Additionally the unload event is already very unreliable (it won't be run in various cases on mobile platforms, and also won't run if the page gets BFCached on Android Chrome, Android Firefox, and Safari (+ probably other WebKit-based browsers), and so it's pretty much a footgun and we considered deprecating it. The header allows web-pages to see what happens if unload never runs in their pages (to prepare for migration), have control over their code and even code they can't necessarily change (e.g. third party libraries), and also ensure that they'll never add any usage of unload in the future (in favor of the alternatives like pagehide/visibilitychange).

cc @domenic @annevk @smaug---- @cdumez @clelland

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions