Speculation rules
Limited availability
Speculation rules are hints to the browser to proactively download pages in the background so they appear instantly when the user navigates to them.
Browser support
- Chrome 109 Released on 2023-01-10
- Chrome Android 109 Released on 2023-01-10
- Edge 109 Released on 2023-01-12
- Firefox Not supported Position: neutral (concerns: complexity) Bugs: 1969396 1969838 2020702
- Firefox for Android Not supported Position: neutral (concerns: complexity) Bugs: 1969838
- Safari Not supported Bugs: 295193
- Safari on iOS Not supported Bugs: 295193
Need this feature?
Leave a 👍 on the feedback issue
Don't forget to also leave a comment explaining your specific use case.
MDN documentation
Specifications
- HTML (#speculation-rules), from HTML Workstream (WHATWG).
- Prerendering Revamped, from Web Platform Incubator Community Group (W3C).
Usage (according to Chrome Platform Status)
~11.706% of page loads. More data at chromestatus.com.Web Platform Tests (WPT)
View the latest WPT test results for this featureSurveys
Developer use cases
-
My company has a web app in which users can create, edit, and save documents. The app's landing page is the documents list, from which users can open their documents in a proprietary editor in a new tab. The editor has many features, so it loads and evaluates several megabytes of assets. Even with request & bytecode caching, loading and evaluating assets is pretty slow. With the Speculation Rules API (specifically prerendering), I can start asset load and evaluation before a user opens their document, and then use the Broadcast Channel API to tell the prerendered page what document to open.
My company has a web app in which users can create, edit, and save documents. The app's landing page is the documents list, from which users can open their documents in a proprietary editor in a new tab. The editor has many features, so it loads and evaluates several megabytes of assets. Even with request & bytecode caching, loading and evaluating assets is pretty slow. With the Speculation Rules API (specifically prerendering), I can start asset load and evaluation before a user opens their document, and then use the Broadcast Channel API to tell the prerendered page what document to open. [see original comment] -
Intelligently prefetch pages using my existing, simple Rails-based stack without cumbersome SPA/ frontend framework dependencies. Unlike the existing prefetch it would be nice to not have to be careful around cache settings in order for this to work.
Intelligently prefetch pages using my existing, simple Rails-based stack without cumbersome SPA/ frontend framework dependencies. Unlike the existing prefetch it would be nice to not have to be careful around cache settings in order for this to work. [see original comment] -
Improve performance for my web apps without resorting to SPA frameworks. Service Workers and Cache API have come a long way towards making MPA apps comparable to SPAs. Speculation rules will close the gap further while providing an ergonomical API.
Improve performance for my web apps without resorting to SPA frameworks. Service Workers and Cache API have come a long way towards making MPA apps comparable to SPAs. Speculation rules will close the gap further while providing an ergonomical API. [see original comment] -
My company's website Imagine.art is made up of several independently deployed Next.js apps served from one origin using Next.js Multi-Zones: a host app rewrites routes for each zone. Inside a zone/Next.js app, `<Link>` prefetches the next page's RSC payload, so navigation is instant. Between zones that isn't possible. Every switch is a full document navigation that goes through the host proxy, the target zone's middleware and a server render. We use the Speculation Rules API to close that gap: - **Document rules with `href_matches`** prefetch each zone's root page as soon as a page links to it (`immediate`), and deeper zone pages on hover (`moderate`). - **Dynamically inserted list rules** cover platform switchers that navigate with `window.location.assign`, where there's no `<a>` to match. - **`Sec-Purpose: prefetch`** lets our middleware refuse prefetches that would refresh a session or rotate a single-use refresh token, so prefetching has no side effects on an authenticated app. In Chromium the difference is dramatic. In our dev environment, a cross-zone navigation served from the prefetch gets its first byte in a few milliseconds and reaches DOMContentLoaded in about 60 ms, versus 2–4 s for the same navigation without it.
My company's website Imagine.art is made up of several independently deployed Next.js apps served from one origin using Next.js Multi-Zones: a host app rewrites routes for each zone. Inside a zone/Next.js app, `<Link>` prefetches the next page's RSC payload, so navigation is instant. Between zones that isn't possible. Every switch is a full document navigation that goes through the host proxy, the target zone's middleware and a server render. We use the Speculation Rules API to close that gap: - **Document rules with `href_matches`** prefetch each zone's root page as soon as a page links to it (`immediate`), and deeper zone pages on hover (`moderate`). - **Dynamically inserted list rules** cover platform switchers that navigate with `window.location.assign`, where there's no `<a>` to match. - **`Sec-Purpose: prefetch`** lets our middleware refuse prefetches that would refresh a session or rotate a single-use refresh token, so prefetching has no side effects on an authenticated app. In Chromium the difference is dramatic. In our dev environment, a cross-zone navigation served from the prefetch gets its first byte in a few milliseconds and reaches DOMContentLoaded in about 60 ms, versus 2–4 s for the same navigation without it. [see original comment]
View as JSON | Edit this feature | Report an issue | Web-features entry: source, dist