Skip to content

Add speculation rules prefetch #11426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Add speculation rules prefetch #11426

wants to merge 2 commits into from

Conversation

domenic
Copy link
Member

@domenic domenic commented Jul 3, 2025

This is an incomplete draft. Progress tracker for what I would consider an acceptable MVP:

  • Speculation rules data model
  • Speculation rules script element integration
  • Speculation rules parsing
  • Speculation-Rules HTTP header
  • Speculation rules processing model
  • Run specfmt to rewrap everything to 100 characters
  • CSP integration pull request
  • Fetch integration pull request (just a new destination value)

This omits actually defining the prefetch operation. I think it would be reasonable to have HTML refer to https://wicg.github.io/nav-speculation/prefetch.html for that temporarily, and then port over that document in a separate PR or two.

I'm posting this now in case it's helpful to people working on implementations in WebKit and Gecko (/cc @yoavweiss @zcorpan).


This ports the relevant text from https://wicg.github.io/nav-speculation/speculation-rules.html, with minor improvements and additions.

Notable changes from that document:

  • Allows treating prerender rules as prefetch rules.

  • Allows the presence of target_hint (a prerender-specific speculation rule key), but ignores it.

  • Follows the precedent set by import maps a bit more closely in how it integrates with the script processing model. Normatively, it fires error events on the script element for the few things that cause complete parsing failures. (Chromium currently does not do this, but we are willing to.)

  • Adds conformance requirements for speculation rules JSON documents, following the precedent set by import maps.

  • Adds explicit callouts for when the implementation may report warnings for parsing failures, following the precedent set by import maps.

  • Fixes a few minor bugs in the parsing algorithms. E.g., the previous text did not correctly deal with how CSS selector parsing returned a list, or called the slightly wrong algorithm for parsing URL patterns.

  • Simplified the processing model for the Speculation-Rules HTTP header. The previous text added various concepts around pending fetches and periodic implementation-defined processing of those fetches, all designed to allow the implementation to de-prioritize these fetches in favor of other things that happen during loading. This version instead explicitly allows an implementation-defined wait time and uses a separate task source which user agents can deprioritize.

  • At least two implementers are interested (and none opposed):
    • Chromium
    • Gecko
    • WebKit is in support of a subset of the functionality here
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: N/A
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): N/A
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): N/A
  • Corresponding HTML AAM & ARIA in HTML issues & PRs: N/A
  • MDN issue is filed: N/A, MDN already documents this well
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


/acknowledgements.html ( diff )
/document-lifecycle.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/references.html ( diff )
/scripting.html ( diff )
/webappapis.html ( diff )

This ports the relevant text from https://wicg.github.io/nav-speculation/speculation-rules.html, with minor improvements and additions.

Notable changes from that document:

* Allows treating prerender rules as prefetch rules.

* Allows the presence of target_hint (a prerender-specific speculation rule key), but ignores it.

* Follows the precedent set by import maps a bit more closely in how it integrates with the script processing model. Normatively, it fires error events on the script element for the few things that cause complete parsing failures.

* Adds conformance requirements for speculation rules JSON documents, following the precedent set by import maps.

* Adds explicit callouts for when the implementation may report warnings for parsing failures, following the precedent set by import maps.

* Fixes a few minor bugs in the parsing algorithms. E.g., the previous text did not correctly deal with how CSS selector parsing returned a list, or called the slightly wrong algorithm for parsing URL patterns.

* Simplified the processing model for the Speculation-Rules HTTP header. The previous text added various concepts around pending fetches and periodic implementation-defined processing of those fetches, all designed to allow the implementation to de-prioritize these fetches in favor of other things that happen during loading. This version instead explicitly allows an implementation-defined wait time and uses a separate task source which user agents can deprioritize.
@domenic domenic added addition/proposal New features or enhancements topic: navigation labels Jul 3, 2025
@domenic domenic marked this pull request as draft July 3, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: navigation
Development

Successfully merging this pull request may close these issues.

1 participant