Instant navigations · senior
Speculation Rules, prefetching and prerendering
The Speculation Rules API lets a page tell Chromium which next pages to prefetch or fully prerender, with an eagerness level, so the next navigation can show with near-zero LCP; it needs care for side effects, analytics and data cost.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Syntax: <script type="speculationrules"> with JSON: { "prerender": [{ "where": { "href_matches": "/product/*" }, "eagerness": "moderate" }] }. Use "prefetch" for a lighter option.
- Eagerness: immediate (as soon as seen), eager, moderate (on desktop about 200 ms hover or pointerdown), conservative (pointer or touch down). Chrome limits how many prerenders run.
- Prefetch downloads the HTML only; prerender loads and renders the page in a hidden tab, including running its JS.
- Support: Chromium (prerender since 109, eagerness since 121). Safari has it behind a flag and Firefox does not ship it, so treat it as progressive enhancement.
- Exclude URLs with side effects (/logout, /add-to-cart links) and be careful with analytics: check document.prerendering and the prerenderingchange event to count views only when shown.
- Framework prefetching (Next.js <Link>) and router caches solve a similar problem inside SPAs.
The red pen
Common traps: mistake → fix
Mistake: "Prerender every link"
Fix: it wastes data and CPU (bad on Indian mobile data plans) and can trigger side effects.
Mistake: "Prefetch and prerender are the same"
Fix: prefetch fetches the document; prerender also renders it and runs its scripts.
Mistake: "It works in all browsers"
Fix: it is Chromium-only; others ignore the rules.
Easy to hard
Questions interviewers ask, easy to hard
- What is the Speculation Rules API?
- Prefetch vs prerender: what is the difference and the cost?
- How do you avoid wrong analytics and side effects from prerendered pages?
- Would you use it on a product listing page in India? With what eagerness, and why?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.