Speculative Loading, Done Properly
Loading the page a visitor is likely to open next before they click, either by prefetching its resources or by fully prerendering it in the background.
On this page
What is at stake
When the prediction is right the next page appears almost instantly, improving every loading metric for that navigation without touching the server.
The playbook
- Start with moderate or conservative eagerness triggered by hover or press
- Prerender only pages that have no side effects when loaded
- Delay analytics and ad calls until a prerendered page is activated
- Exclude logout, cart and account actions from the rules
- Measure navigation timings before and after
Where it goes wrong
Avoid:
- Prerendering every link on a page
- Speculating URLs that change state on the server
- Counting prerendered pages as views before anyone sees them
- Using speculation to hide a slow server
The numbers behind it
| Measure | Figure |
|---|---|
| Speculation Rules API | a JSON script block listing URLs or patterns to prefetch or prerender |
| Browser support | Chromium-based browsers; other browsers ignore the rules safely |
| eagerness setting | ranges from immediate to conservative and controls when speculation starts |
| Prerender cost | uses memory and bandwidth, and runs the page's scripts |
| Detecting prerendering | document.prerendering and the prerenderingchange event |
Getting outside help
When to hand it over: Bring in help when analytics numbers change after adding speculation rules, or when pages have side effects that make prerendering unsafe.
Where this comes from
- Chrome for Developers — Prerender pages in Chrome for instant page navigations
- MDN Web Docs — Speculation Rules API
The figures and practices above come from the sources listed.
Working on something like this?
We take on Performance & Accessibility work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.