Speculation Rules API — screenshot of developer.mozilla.org

Speculation Rules API

The Speculation Rules API allows me to explicitly tell the browser which pages to prefetch or prerender, significantly improving future navigation performance for MPAs. It offers a more expressive and configurable way to accelerate page loads compared to older methods.

Visit developer.mozilla.org →

Questions & Answers

What is the Speculation Rules API?
The Speculation Rules API is a web platform feature that allows developers to inform browsers which URLs should be prefetched or prerendered. This proactive loading of content improves subsequent navigation performance by reducing perceived loading times for users.
Who should use the Speculation Rules API?
This API is primarily designed for multi-page applications (MPAs) to optimize navigation between different documents. It's beneficial for sites where users frequently move between a predictable set of pages.
How does the Speculation Rules API compare to <link rel="prefetch"> or <link rel="prerender">?
It offers a more expressive and configurable syntax than older <link> tags. Unlike <link rel="prefetch">, it can be used for cross-site navigations and isn't blocked by Cache-Control headers. It also supersedes the deprecated Chrome-only <link rel="prerender">.
When should I implement the Speculation Rules API?
You should implement it when you want to significantly reduce navigation times for anticipated user journeys within your multi-page application. Use it to prefetch or prerender pages that users are highly likely to visit next, such as product pages from a listing or steps in a checkout flow.
How are speculation rules specified?
Speculation rules are specified as a JSON structure within an inline <script type="speculationrules"> element or via an external text file referenced by the Speculation-Rules HTTP response header. The external file must be served with an application/speculationrules+json MIME type.