Check 06.25 · Performance and Core Web Vitals

Preload likely navigations with Speculation Rules

Declare Speculation Rules to prefetch or prerender the next pages, exclude URLs with side effects and check the result in Chrome.

Priority
Important
Difficulty
Intermediate
Estimated time
1 to 3 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

The Speculation Rules API lets a page tell the browser which pages it may load ahead of time: either download their HTML (prefetch) or render them fully in an invisible tab (prerender). When the visitor clicks, the next page appears faster, sometimes instantly. Once this check is done, safe internal links are covered by a rule, URLs with side effects are excluded from it and your analytics do not count pages nobody ever saw.

Why it matters

A standard navigation starts at the click: request, server wait, HTML download, then the resources. With a speculation rule, the browser does part of that work before the click, while the visitor is hovering over or touching the link.

The two actions differ in both cost and risk:

Action What the browser does Cost Risk
prefetch Downloads the HTML document only, without executing it One request to the server Low: no JavaScript runs
prerender Loads and renders the full page, subresources and scripts included Memory, CPU, bandwidth Higher: scripts run before the visit

A rule designates its targets in two ways: a list of URLs (urls) or a condition applied to the links on the page (where, known as a document rule). The eagerness field sets when the speculation is triggered. According to the Chrome documentation:

eagerness Trigger in Chrome
immediate As soon as the rule is read. Default for list rules
eager On desktop, after a very brief hover; on mobile, shortly after the link enters the viewport
moderate On desktop, after a hover of about 200 ms; on mobile, based on viewport heuristics
conservative When the click or touch begins. Default for document rules

As of November 2026, only Chromium-based browsers (Chrome, Edge, Opera) apply these rules in their current versions. WebKit and Mozilla are working on same-origin prefetch; check the status of Safari and Firefox in the MDN compatibility table, linked at the bottom of this guide. A browser that does not know the API ignores the block without raising an error.

Chrome may also decide not to preload anything (data saver or energy saver, insufficient memory, “Preload pages” setting turned off), and it caps the number of concurrent speculations.

What it improves

  • LCP (Largest Contentful Paint, rendering of the largest visible element) On a prerendered page, Core Web Vitals are measured from activation, which often gives an LCP close to zero. With prefetch, the gain is on the document's response time. See target an LCP of 2.5 s (opens in a new tab).
  • TTFB (Time to First Byte) of internal navigations: the HTML is already there when the click happens.
  • Scope Only navigations that start from a page of your site are affected. The first page viewed, the one reached from a search engine, gains nothing from your rules.
  • Rankings Indirect effect. Chrome's field data includes these faster navigations, and Core Web Vitals are only one signal among many others.
  • Costs Extra requests to the server for pages that will not all be visited. The more aggressive the eagerness, the higher this overhead.

How to check

In Chrome, open DevTools, Application panel, Background services > Speculative loads section:

  • the Rules tab lists the rule sets detected on the page, including those injected by a CMS or a CDN;
  • the Speculations tab lists each targeted URL, the action and its status (Not triggered, Ready, Failure with the reason);
  • the Speculative loads tab tells you whether the current page was itself prefetched or prerendered.

Hover over a link, check that its status changes to Ready, then click. Check the headers too, because the rule may come from the HTTP response:

curl -s -o /dev/null -D - https://example.com/ | grep -i "speculation-rules"

On the server side, speculative requests carry the Sec-Purpose: prefetch header (prefetch) or Sec-Purpose: prefetch;prerender (prerender). Add it to your access logs to measure the extra volume.

Inside a page, this test tells you whether it was prerendered:

const navigation = performance.getEntriesByType('navigation')[0];
console.log(document.prerendering || navigation.activationStart > 0);

How to implement

Before you start

List the URLs that a plain GET request must never trigger ahead of time:

  • logging out, switching language or currency through a link, adding to the cart through a link;
  • sending a code by text message or email, counting down a quota of free articles;
  • pages whose content depends on a state that has just changed (cart, account, stock).

Start with prefetch and moderate or conservative. Keep prerender for pages where you control every script. Starter block, to place in the shared template:

<script type="speculationrules">
{
  "prefetch": [
    {
      "where": {
        "and": [
          { "href_matches": "/*" },
          { "not": { "href_matches": ["/deconnexion", "/panier/*", "/compte/*", "/*\\?(.+)"] } },
          { "not": { "selector_matches": ".no-prefetch, [rel~=nofollow]" } }
        ]
      },
      "eagerness": "moderate"
    }
  ]
}
</script>

The block must be valid JSON: one stray comma and the whole rule set is ignored. If the site sends a Content Security Policy, allow the block with the 'inline-speculation-rules' keyword in script-src, or use the HTTP header described in the Apache and Nginx sections.

Protect analytics and ads

With prefetch, no script runs: there is nothing to do. With prerender, any script not designed for this case counts a visit that may never happen. According to Chrome, Google Analytics and Google Publisher Tag already wait for activation. For everything else, delay execution:

function demarrerMesure() {
  // initialize the analytics tool
}

if (document.prerendering) {
  document.addEventListener('prerenderingchange', demarrerMesure, { once: true });
} else {
  demarrerMesure();
}

Cancel after a state change

A page preloaded before an add to cart or a login shows a stale state. On the response that changes that state, send Clear-Site-Data: "prefetchCache", "prerenderCache": Chrome discards its pending speculations. Support for these directives is recent and specific to Chromium; check it in the Chrome documentation.

WordPress

Versions WordPress 6.8 and later.

Speculative loading has been built into core since WordPress 6.8: prefetch with conservative on internal links. It is disabled for logged-in users and on sites without pretty permalinks, and it ignores URLs with query parameters. A block can opt out with the no-prefetch or no-prerender CSS class.

To exclude paths or change the mode, add the following to a plugin or to the child theme's functions.php:

add_filter('wp_speculation_rules_href_exclude_paths', function (array $paths): array {
    $paths[] = '/panier/*';
    $paths[] = '/commande/*';

    return $paths;
});

add_filter('wp_speculation_rules_configuration', function (?array $config): ?array {
    if ($config === null) {
        return null;
    }

    $config['mode'] = 'prefetch';
    $config['eagerness'] = 'moderate';

    return $config;
});

Returning null in the second filter turns the feature off. The Speculative Loading plugin from the Performance team adds a settings page and defaults to prerender with moderate: more gain, more risk for analytics scripts.

Cloudflare

Versions Cloudflare dashboard, all plans (Speed Brain enabled by default on the Free plan), November 2026.

Speed Brain adds a Speculation-Rules header to pages, pointing to a prefetch rule set to conservative on same-site links. Setting: Speed > Settings, Content Optimization section, Speed Brain toggle.

  • Prefetches are served only from Cloudflare's cache and never reach the origin: without HTML caching, Speed Brain brings nothing. See configure browser and server caching (opens in a new tab).
  • If the origin already sends its own Speculation-Rules header, Cloudflare leaves it as is.
  • The documentation lists other limitations (routes going through a Worker, some Content Security Policies).

Shopify

Versions Shopify stores with a Liquid theme, all plans, November 2026.

Since June 2025, Shopify has sent a Speculation-Rules header on all Liquid stores: prefetch set to conservative. The platform also sends Clear-Site-Data when the cart changes. To go further, add your rules to the <head> of layout/theme.liquid; they are combined with Shopify's:

<script type="speculationrules">
{
  "prerender": [
    {
      "where": { "selector_matches": "[data-instant-navigation]" },
      "eagerness": "moderate"
    }
  ]
}
</script>

Then set the data-instant-navigation attribute on links that are very likely to be clicked, for example the product cards of a collection. Test the installed apps: those that inject tracking may count prerendered pages.

Laravel

Versions Laravel 11 to 13.

Paste the starter block into the Blade layout, before </head>, adapting the excluded paths. Laravel declares no rule by default. Check that no GET route has a side effect: logout in the starter kits goes through POST, but a signed link or a language-switching route may have one. To make a route refuse every speculative request, respond with an error, which cancels the speculation:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class RejectSpeculativeRequests
{
    public function handle(Request $request, Closure $next): Response
    {
        if ($request->headers->has('Sec-Purpose')) {
            abort(Response::HTTP_SERVICE_UNAVAILABLE);
        }

        return $next($request);
    }
}

Next.js

Versions Next.js 15 and 16 (App Router).

Navigations between pages go through the client-side router, and the <Link> component already prefetches visible routes in production. Speculation Rules only apply to navigations that load a new document: they are therefore only useful for plain <a> links or for entering the application from another site you manage.

Nuxt

Versions Nuxt 3 and 4.

Same logic: <NuxtLink> prefetches internal routes and navigation stays on the client side. An experimental option, experimental.crossOriginPrefetch, relies on the Speculation Rules API for links to another origin; its behavior is described on Nuxt's experimental features page.

Astro

Versions Astro 4.2 and later (experimental clientPrerender option).

Astro produces separate pages: the rules apply to them in full. The built-in prefetching uses <link rel="prefetch">; the experimental option switches it to Speculation Rules prerendering wherever the browser allows it:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  prefetch: {
    prefetchAll: true,
    defaultStrategy: 'hover',
  },
  experimental: {
    clientPrerender: true,
  },
});

A link opts out with data-astro-prefetch="false".

Apache

Versions Apache 2.4 (mod_headers), header supported by Chrome 121 and later.

The Speculation-Rules header saves you from touching the templates. Create /speculation-rules.json at the root with the JSON content of the starter block, then:

<Files "speculation-rules.json">
    ForceType application/speculationrules+json
</Files>

<IfModule mod_headers.c>
    Header set Speculation-Rules "\"/speculation-rules.json\"" "expr=%{CONTENT_TYPE} =~ m#text/html#i"
</IfModule>

The application/speculationrules+json MIME type is mandatory, as are the quotation marks around the URL.

Nginx

Versions Nginx 1.18 and later, header supported by Chrome 121 and later.

location = /speculation-rules.json {
    types { }
    default_type application/speculationrules+json;
}

add_header Speculation-Rules '"/speculation-rules.json"';

Place add_header in the location block that serves the HTML: an add_header directive in a child block cancels those inherited from the parent. Reload with sudo nginx -t && sudo systemctl reload nginx.

Common mistakes

  • Prerendering the whole site with immediate: server load multiplied, and Chrome caps the number of speculations anyway.
  • Forgetting links with side effects: a hover is then enough to log the visitor out or fill their cart.
  • Switching to prerender without testing third-party scripts: inflated page views and ad impressions. See limit third-party scripts (opens in a new tab).
  • Stacking rules without knowing it: WordPress core, a plugin, Speed Brain and the theme all add up. The Rules tab shows everything that applies.
  • Counting on the rules for the arrival from Google: they only act on the navigations that follow. Going back relies on a different mechanism: make pages eligible for the bfcache (opens in a new tab).

Frequently asked questions

Should I choose prefetch or prerender?

Start with prefetch. It downloads only the HTML document, without running any script: the risk is limited to URLs where the request alone has a side effect. Prerender renders the whole page and gives the fastest navigations, but it runs your scripts and third-party ones before the visit. Keep it for links that are very likely to be clicked, after checking your analytics tools and ads.

Do Speculation Rules work in Safari and Firefox?

As of November 2026, Speculation Rules are only applied by Chromium-based browsers, such as Chrome, Edge and Opera, in their current versions. The WebKit and Mozilla teams are working on same-origin prefetch. Other browsers ignore the block without raising an error: you can deploy it safely, knowing that only some of your visitors benefit. Check the MDN compatibility table.

Do Speculation Rules improve SEO?

Indirectly. Speculation Rules speed up internal navigations in Chrome, which improves the LCP measured in the field for those page views. Core Web Vitals are one ranking signal among many others, with a modest effect. The landing page reached from a search engine is not sped up by your own rules, and crawlers do not use them.

Does preloading skew visit statistics?

With prefetch, no: no script runs until the visitor has clicked. With prerender, scripts run before the visit; an analytics tool not designed for this case then counts pages nobody ever saw. Google Analytics waits for the page to be activated. For other tools, start measuring on the prerenderingchange event when document.prerendering is true.

Updated on

Topic checklist (PDF)

And now?

In the “Performance and Core Web Vitals” topic

  1. Analyze PageSpeed Insights and Lighthouse
  2. Analyze real-user CrUX data
  3. Target LCP ≤ 2.5 s at the 75th percentile
  4. Target INP ≤ 200 ms at the 75th percentile
  5. Target CLS ≤ 0.1 at the 75th percentile
  6. Target TTFB ≤ 800 ms as a benchmark
  7. Optimize hosting and CDN
  8. Enable Brotli/Gzip
  9. Configure browser and server caching
  10. Minify CSS and JavaScript
  11. Remove unused CSS/JS
  12. Reduce render-blocking resources
  13. Defer non-essential scripts
  14. Limit third-party scripts
  15. Optimize database queries
  16. Optimize fonts (WOFF2, font-display)
  17. Preload only critical resources
  18. Optimize the LCP image without lazy loading
  19. Lazy-load offscreen content
  20. Reserve space for media and ads
  21. Reduce DOM complexity
  22. Test before and after cookie consent
  23. Test on a slow mobile connection
  24. Set a performance budget
  25. Preload likely navigations with Speculation Rules
  26. Make pages eligible for the back/forward cache (bfcache)
  27. Diagnose INP with Long Animation Frames (LoAF)