Skip to content
Performance & Accessibility

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.

MediaScaleUp Editorial Team 2 min read 14 views
Speculative Loading, Done Properly

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

  1. Start with moderate or conservative eagerness triggered by hover or press
  2. Prerender only pages that have no side effects when loaded
  3. Delay analytics and ad calls until a prerendered page is activated
  4. Exclude logout, cart and account actions from the rules
  5. 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
What to do and what to avoid with speculative loading, side by side
Good practice against the usual mistakes, from the sources listed below.

The numbers behind it

Published figures for Speculative Loading
MeasureFigure
Speculation Rules APIa JSON script block listing URLs or patterns to prefetch or prerender
Browser supportChromium-based browsers; other browsers ignore the rules safely
eagerness settingranges from immediate to conservative and controls when speculation starts
Prerender costuses memory and bandwidth, and runs the page's scripts
Detecting prerenderingdocument.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

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.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Performance & Accessibility