Skip to content

Add an API to opt-out of back-forward cache? #5744

@rakina

Description

@rakina

Currently, we only have "implicit" ways to opt-out of bfcache that might have other side effects. A few examples from Firefox's bfcache page and problems associated with them:

  • The page uses an unload or beforeunload handler
    • This is not an opt-out signal on Safari and Chrome's back-forward cache. It is very easy to "accidentally" opt-out of bfcache with this, as ~66% of pages have an unload handler registered, causing these pages to unintentionally lose potential back-navigation improvements. Existence of these handlers only for the sake of opting out of bfcache is also bad because it might slow down navigations (as the browser need to fire these events), etc.
  • The page sets "cache-control: no-store"
    • This is an opt-out signal on Safari and Chrome's back-forward cache, however, this is doing way more than just opt-out of bfcache. This opts-out the site of getting stored in any cache, which might not be ideal if it only wants to opt-out of the bfcache case. Similar to unload and beforeunload, a lot of websites also use this for non-bfcache reasons, and might unknowingly opt-out of bfcache.

I think having an explicit API to specifically opt-out of bfcache (and does nothing more than that) might be good, since there might be legitimate cases of not wanting to be bfcached (stale data/state of the previous page, logging in/out, etc.) specifically. On top of the above points, web developers have been having a hard time finding a reliable way to do just that. See [1] [2] [3] [4]. Also, as people start adopting the explicit API, we can slowly move away from the implicit opt-outs entirely so that pages aren't unintentionally opting-out of bfcache's potential performance improvements?

Maybe we can have something like history.disableBFCache()? (thanks @annevk for suggesting this!)

This might also be a good starting point into standardizing back-forward cache behavior across browsers. I'm not quite sure how much of the behavior is specced currently, but there certainly are some noticeable behavior difference between Firefox, Safari, and Chrome's implementation of bfcache (even in the opt-out signals, as mentioned above). I hope we can make the behavior more predictable and interoperable in the future :) - update: For other bfcache-related issues, see #5880. This thread will focus specifically on opt-out.

cc @annevk @smaug---- @mystor @cdumez @beidson @hober @altimin @xharaken @fergald

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions