Speculation rules
Speculation rules are hints to the browser to proactively download pages in the background so they appear instantly when the user navigates to them. It is most useful when native HTML semantics or browser capabilities can replace custom implementation work.
Overview
Speculation rules are hints to the browser to proactively download pages in the background so they appear instantly when the user navigates to them. It is most useful when native HTML semantics or browser capabilities can replace custom implementation work.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
api.Document.prerendering Experimental | 108 | 108 | | | 108 | |
| DOM API | ||||||
prerenderingchange_event Experimental The prerenderingchange event is fired on a prerendered document when it is activated (i.e., the user views the page). | 108 | 108 | | | 108 | |
activationStart Experimental The activationStart read-only property represents the time between when a document starts prerendering and when it is activated. | 108 | 108 | | | 57 | |
destination (speculationrules) Experimental `speculationrules` value | 121 | 121 | | 26.2 | 121 | 26.2 |
| Other | ||||||
html.elements.script.type.speculationrules Experimental The speculationrules value of the type attribute of the element indicates that the body of the element contains speculation rules. | 109 | 109 | | 26.2 | 109 | 26.2 |
html.elements.script.type.speculationrules.eagerness Experimental `eagerness` key | 121 | 121 | | 26.2 | 121 | 26.2 |
| `expects_no_vary_search` key | 127 | 127 | | | 127 | |
html.elements.script.type.speculationrules.prefetch Experimental `prefetch` key | 110 | 110 | | 26.2 | 103 | 26.2 |
html.elements.script.type.speculationrules.prerender Experimental `prerender` key | 105 | 105 | | | 103 | |
| `referrer_policy` key | 111 | 111 | | 26.2 | 111 | 26.2 |
| `relative_to` key | 121 | 121 | | 26.2 | 121 | 26.2 |
html.elements.script.type.speculationrules.requires Experimental `requires` key | 110 | 110 | | | 103 | |
html.elements.script.type.speculationrules.requires.anonymous-client-ip-when-cross-origin Experimental `anonymous-client-ip-when-cross-origin` value | 110 | | | | 103 | |
| `source` key is optional | 122 | 122 | | 26.2 | 122 | 26.2 |
html.elements.script.type.speculationrules.tag Experimental `tag` key | 136 | 136 | | 26.2 | 136 | 26.2 |
| `target_hint` key | 138 | 138 | | | 138 | |
html.elements.script.type.speculationrules.urls Experimental `urls` key | 109 | 109 | | 26.2 | 103 | 26.2 |
html.elements.script.type.speculationrules.where Experimental `where` key | 121 | 121 | | 26.2 | 121 | 26.2 |
http.headers.Content-Security-Policy.script-src.inline-speculation-rules Experimental `inline-speculation-rules` source expression | 110 | 110 | | 26.2 | 110 | 26.2 |
http.headers.Sec-Purpose.speculationrules Experimental `Sec-Purpose` for `<script type="speculationrules">` prefetch | 110 | 110 | | 26.2 | 110 | 26.2 |
http.headers.Sec-Speculation-Tags Experimental The HTTP Sec-Speculation-Tags request header contains one or more tag values from the speculation rules that resulted in the speculation. This allows a server to identify which rule(s) caused a speculation and potentially block them. | 136 | 136 | | 26.2 | 136 | 26.2 |
http.headers.Speculation-Rules Experimental The HTTP Speculation-Rules response header provides one or more URLs pointing to text resources containing speculation rule JSON definitions. When the response is an HTML document, these rules will be added to the document's speculation rule set. See the Speculation Rules API for more information. | 121 | 121 | | 26.2 | 121 | 26.2 |
http.headers.Supports-Loading-Mode Experimental The HTTP Supports-Loading-Mode response header allows a response to opt-in to being loaded in a novel, higher-risk context that it would otherwise fail to be loaded in. | 109 | 109 | | | 109 | |
http.headers.Supports-Loading-Mode.credentialed-prerender Experimental `credentialed-prerender` directive | 109 | 109 | | | 109 | |
http.headers.Supports-Loading-Mode.fenced-frame Experimental `fenced-frame` directive | 117 | 117 | | | 117 | |
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- This browser only partially implements this feature
- This feature was removed in a later browser version (109)
- Initial support included same-origin prerendering only.
- This browser only partially implements this feature
- This feature was removed in a later browser version (109)
- Initial support included same-origin prerendering only.
- Requires an experimental browser flag to be enabled
- This browser only partially implements this feature
- This feature was removed in a later browser version (109)
- Initial support included same-origin prerendering only.
- Requires an experimental browser flag to be enabled
- This browser only partially implements this feature
- Requires an experimental browser flag to be enabled
- Only `conservative` is supported for document rules (though `moderate` automatically falls back to `conservative`). Only `eager` and `immediate` is supported for list rules.
- This browser only partially implements this feature
- Requires an experimental browser flag to be enabled
- Only `conservative` is supported for document rules (though `moderate` automatically falls back to `conservative`). Only `eager` and `immediate` is supported for list rules.
- This browser only partially implements this feature
- This feature was removed in a later browser version (127)
- Supported for `prefetch` only.
- This browser only partially implements this feature
- This feature was removed in a later browser version (127)
- Supported for `prefetch` only.
- This browser only partially implements this feature
- This feature was removed in a later browser version (127)
- Supported for `prefetch` only.
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- This browser only partially implements this feature
- Only `"_blank"` and `"_self"` are supported and only for prefetch.
- This browser only partially implements this feature
- Only `"_blank"` and `"_self"` are supported and only for prefetch.
- This browser only partially implements this feature
- Only `"_blank"` and `"_self"` are supported and only for prefetch.
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
- Requires an experimental browser flag to be enabled
Syntax
<script type="speculationrules">
{
"prerender": [{ "where": { "href_matches": "/articles/*" } }],
"prefetch": [{ "urls": ["/next-page"] }]
}
</script> Live demo
Speculation strategy
Show how rules can tell the browser which navigations are good candidates for prefetch or prerender.
Where it helps
Speculation rules work best on predictable navigation paths such as search results or article lists.
Guardrails
Speculative loading consumes bandwidth and memory, so use it selectively.
Use cases
Control document behavior
Use Speculation rules to influence loading, metadata, or script behavior at the document level.
Tune performance strategy
Apply Speculation rules when earlier resource hints or document settings improve startup or runtime behavior.
Cautions
- Test Speculation rules in your target browsers and input environments before depending on it as a primary behavior.
- Provide a fallback path or acceptable degradation strategy when support is still limited.
Accessibility
- Make sure Speculation rules supports the intended task without making the page harder to perceive, understand, or operate.
Related links
Powered by web-features