Skip to content

Add ability to opt-out of back-forward cache #1917

@KthProg

Description

@KthProg

What problem are you trying to solve?

Users sometimes use back navigation to reach previous pages, when the portions of the page state loaded via fetch have been updated since their previous navigation. The result is a page with stale data, especially for SSR web applications with some dynamic content, where the full page itself is usually cached.

Lots of fetch requests should be cached, but should not be pulled from previously cached versions on back navigation, e.g. a user's cart. Being able to provide a hint to the fetch API/browser that a fetch request should not be bf-cached would be very helpful.

What solutions exist today?

  • You can set cache-control headers, but most browsers seem to ignore these when using bfcache
  • You can set cache: 'no-store' on the fetch request, but Safari definitely ignores this when using bfcache, and it can result in never caching a response when that's not the optimal behavior in many cases
  • You can listen to the pageshow event and check if the page was persisted, and trigger your API request, but you have to do this manually for every request you want to re-run

How would you solve it?

I would add an additional bfcache property to the request init object, with values like 'no-store'.

Anything else?

See this related issue:
whatwg/html#5744

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions