Skip to content

Route prefetching

Prefetching loads a route's code and data before the click, on hover, focus, or when the link enters the viewport. In principle it helps the next navigation rather than the first paint, so it matters for how fast the app feels once someone starts clicking.

05 / 14First-paint leverOne of 7 features that affect first paint, the moment the browser first draws content. Together they are worth 14 of the 28 points.

Labels across 23 frameworks

  • 1st-party19
  • Experimental1
  • Third-party0
  • Manual3
  • of 23

How to enable it, by framework

One card per framework, in the same order on every feature page. Where a framework has no built-in support (Manual), a short example shows how to build it yourself.

Next

1st-party2 ptsOverview

Set partialPrefetching (needs cacheComponents; 16.3+), pass prefetch={true} on high-value links (<Link>), and optionally add the FastLink mouse-down navigation.

const nextConfig: NextConfig = {
  cacheComponents: true,
  partialPrefetching: true,
};
<FastLink href={href} prefetch={true}>

Adapted from this repo's next-books/next.config.ts (other options omitted) and features/book/components/book-pagination.tsx (href expression simplified; other props omitted); FastLink is this repo's wrapper around Link.

Nuxt

Experimental1 ptOverview

Use <NuxtLink> prefetch-on="visibility" | "interaction", _payload.json payload prefetch, and experimental.prefetchPreloadTags (experimental, off by default).

<FastLink :prefetch-on="eagerPrefetch ? 'visibility' : 'interaction'" :to="href">
experimental: {
  prefetchPreloadTags: true,
},

From this repo's nuxt-books/app/components/BookCard.vue (FastLink is this repo's wrapper around NuxtLink; class omitted) and nuxt.config.ts (optimized branch; early404 omitted).

SvelteKit

1st-party2 ptsOverview

Set data-sveltekit-preload-data="hover". This repo's FastLink wrapper maps a preload prop to that attribute per link ('hover' or 'off'); the pagination and sidebar links pass it explicitly and book cards pass preload={eagerPrefetch}. The starter template already sets the attribute on <body>, and JS/CSS are preloaded automatically (performance).

<body data-sveltekit-preload-data="hover">

From this repo's svelte-books/src/app.html (optimized branch; class attribute omitted).

SolidStart

1st-party2 ptsOverview

Solid Router v1 and the 2.0.0-next.21 prerelease this port pins preload on hover (~20ms) and focus by default. In Solid Router 2.0 stable (npm latest 2.0.1) link preloading is opt-in: createRouter({ routes, preloadLinks: intentPreload() }), with tapPreload, viewportPreload and eagerPreload as other strategies. usePreloadRoute is the manual API, and this port's FastLink calls it on hover and focus (and eagerly when its prefetch prop is set), and starts the navigation on mouse-down.

import { useNavigate, usePreloadRoute } from "@solidjs/router";

From this repo's solid-books/src/components/ui/fast-link.tsx (optimized branch).

Router preloading is off by default; defaultPreload: 'intent' | 'viewport' | 'render' turns it on. This port sets 'intent' and wraps links with FastLink.

const router = createTanStackRouter({
  routeTree,
  defaultPreload: 'intent',
})

From this repo's tanstack-books/src/router.tsx (optimized branch; other options omitted).

The same router preloading applies. This port sets defaultPreload: 'intent' in tanstack-solid-books/src/router.tsx (optimized branch) with @tanstack/solid-router, but it does not use the router's <Link>: its FastLink (src/components/ui/fast-link.tsx) is a plain <a> that calls router.preloadRoute() on hover and focus (and on render when prefetch is set), so preloading is wired by hand through the manual API rather than by the defaultPreload setting.

Code example

defaultPreload: 'intent' makes every router <Link> preload its route on hover or focus. The port's FastLink is a plain <a>, so it calls router.preloadRoute() itself on the same events.

// src/router.tsx
const router = createTanStackRouter({
  routeTree,
  defaultPreload: 'intent',
  defaultPreloadStaleTime: 0,
})
// src/components/ui/fast-link.tsx
const router = useRouter()

function warm() {
  const url = new URL(props.href, 'http://tanstack-solid-books.local')
  const id = url.pathname === '/' ? undefined : url.pathname.slice(1)
  const search = Object.fromEntries(url.searchParams)
  void router
    .preloadRoute(id ? { to: '/$id', params: { id }, search } : { to: '/', search })
    .catch(() => {})
}

return <a href={props.href} onFocus={warm} onMouseEnter={warm}>{props.children}</a>

Source: TanStack Router: Preloading

Pracht

1st-party2 ptsOverview

Use the prefetch route option or <Link> prop; the default is intent (hover is an alias), with viewport, none, and link-only render also available.

<Link route="book" prefetch={eagerPrefetch ? 'viewport' : 'intent'} />

Adapted from this repo's pracht-books/src/features/book/components/book-card.tsx (optimized branch; other props omitted).

Waku

1st-party2 ptsOverview

router.prefetch() is the manual API, documented under useRouter with no experimental marker. The navigation-prefetching guide is tagged Experimental and says its prefetch and instant-navigation props are experimental: the Link helpers are unstable_prefetchOnEnter / unstable_prefetchOnView, and Link prefetch is off unless a prop is set. This port uses the props on FastLink and HoverPrefetchLink.

<Link
  to={hrefToTarget(href)}
  unstable_prefetchOnEnter={prefetchOnEnter}
  unstable_prefetchOnView={prefetchOnView}
/>

From this repo's waku-books/src/components/ui/fast-link.tsx (optimized branch; other props omitted).

Ember

Manual0 ptsOverview

Nothing to enable, and no first-party prefetch is documented: the linking-between-routes guide describes <LinkTo> without prefetching; you wire it yourself with a custom modifier or service.

Code example

Write an ember-modifier that starts the book request on hover or focus and caches the promise. The route's model hook then reads the same cached promise. <LinkTo> passes the modifier through to its <a>.

// app/lib/book/load-catalog.js
const bookCache = new Map();
export function prefetchBook(id, searchParams) {
  const key = `${id}?${stringifySearchParams(searchParams)}`;
  if (!bookCache.has(key)) bookCache.set(key, loadBook(id, searchParams));
  return bookCache.get(key);
}

// app/modifiers/prefetch-book.js
import { modifier } from 'ember-modifier';
import { prefetchBook } from '../lib/book/load-catalog';

export default modifier((element, [id, searchParams]) => {
  const warm = () => prefetchBook(id, searchParams);
  element.addEventListener('pointerenter', warm, { once: true });
  element.addEventListener('focus', warm, { once: true });
  return () => {
    element.removeEventListener('pointerenter', warm);
    element.removeEventListener('focus', warm);
  };
});

// app/routes/book.js: model(params) { return prefetchBook(params.id, parseSearchParams(params)); }
// app/components/book/book-card.gjs
<LinkTo @route="book" @model={{this.bookId}} @query={{this.query}}
        {{prefetchBook this.bookId @searchParams}}>
  {{! … }}
</LinkTo>

Astro

1st-party2 ptsOverview

prefetch: true adds the script; links opt in via data-astro-prefetch or prefetch.prefetchAll: true. Strategies hover (default), tap, viewport, load; falls back to tap on data saver. <ClientRouter /> pages prefetch by default. eagerness and Speculation Rules need experimental clientPrerender. (prefetch)

Code example

prefetch: true turns on the prefetch script. Links opt in with data-astro-prefetch and a strategy, or prefetchAll covers every link.

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

export default defineConfig({
  prefetch: {
    prefetchAll: true,
    defaultStrategy: 'viewport', // 'hover' (default) | 'tap' | 'viewport' | 'load'
  },
});
<!-- src/components/Nav.astro -->
<a href="/books" data-astro-prefetch="tap">Books</a>
<a href="/account" data-astro-prefetch="false">Account</a>

Source: Astro: Prefetch

React Router

1st-party2 ptsOverview

<Link prefetch="none|intent|render|viewport">, default none, uses <link rel="prefetch">. Lazy route discovery is on by default and batch-discovers rendered links; discover="none" opts out. (Link, lazy-route-discovery, react-router.config.ts)

Code example

Set prefetch on <Link>. "intent" loads the route module and data on hover or focus, "viewport" when the link scrolls into view, and "render" as soon as it renders. The port wraps <Link> in its own FastLink.

// app/components/ui/fast-link.tsx
import { Link } from 'react-router'
// …
export function FastLink({ href, prefetch = 'intent', ...rest }: Props) {
  return (
    <Link
      prefetch={prefetch === false ? 'none' : prefetch === true ? 'intent' : prefetch}
      to={href}
      {...rest}
    />
  )
}

Source: React Router: Link

Qwik City

1st-party2 ptsOverview

<Link> prefetches on hover by default (prefetch={false} disables). The preloader adds <link rel="modulepreload"> for handlers and dependencies using a bundle graph; works only in preview/production builds. (routing, modules-prefetching, speculative-module-fetching)

Code example

<Link> starts prefetching the next page when the user hovers it. Set prefetch={false} to turn that off for one link.

// src/components/nav/nav.tsx
import { component$ } from '@builder.io/qwik'
import { Link } from '@builder.io/qwik-city'

export const Nav = component$(() => (
  <nav>
    <Link href="/books">Books</Link>
    <Link href="/account" prefetch={false}>Account</Link>
  </nav>
))

Source: Qwik: Routing

Angular (SSR)

1st-party2 ptsOverview

Opt-in withPreloading(PreloadAllModules) preloads lazy route chunks; @defer has prefetch on idle/viewport/hover. No link hover/viewport prefetch documented. The default strategy is NoPreloading, so nothing is preloaded until withPreloading(...) is added. (NoPreloading, PreloadAllModules, defer)

Code example

The router preloads nothing by default (NoPreloading). Add withPreloading(PreloadAllModules) to fetch every lazy route chunk after the app starts. @defer blocks take their own prefetch trigger.

// src/app/app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideRouter, withPreloading, PreloadAllModules } from '@angular/router';
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [provideRouter(routes, withPreloading(PreloadAllModules))],
};
<!-- any template: load the chunk on interaction, prefetch it when the browser is idle -->
@defer (on interaction; prefetch on idle) {
  <app-book-reviews />
} @placeholder {
  <button>Show reviews</button>
}

Source: Angular: Customizing route behavior

Marko

Manual0 ptsOverview

No prefetch/preload API in the Marko Run docs or full reference. Lazy load triggers (visible, idle, media, events) defer a tag's JS only; that is not route prefetch. (lazy-loading)

Code example

Marko Run navigates with full documents, so a Speculation Rules block in the layout handles it. Supporting browsers prefetch same-origin links on hover; the others ignore the block.

// src/routes/+layout.marko
<head>
  // …
  <html-script type="speculationrules">
    {
      "prefetch": [{
        "where": { "and": [
          { "href_matches": "/*" },
          { "not": { "selector_matches": "[rel~=nofollow]" } }
        ]},
        "eagerness": "moderate"
      }]
    }
  </html-script>
</head>

Source: MDN: speculationrules

Fresh

Manual0 ptsOverview

No first-party prefetch documented; partials (f-client-nav, f-partial) fetch on click only. (partials)

Code example

Add a Speculation Rules block to _app.tsx. Supporting browsers prefetch same-origin pages on hover, and other browsers ignore it. The prefetch only helps full-page navigations, so it does not speed up links that use Fresh partials (f-client-nav).

// routes/_app.tsx
const speculationRules = JSON.stringify({
  prefetch: [{
    where: { and: [
      { href_matches: "/*" },
      { not: { selector_matches: "[rel~=nofollow]" } },
    ] },
    eagerness: "moderate",
  }],
});

// … inside <head>:
<script type="speculationrules" dangerouslySetInnerHTML={{ __html: speculationRules }} />

Source: MDN: speculationrules

Analog

1st-party2 ptsOverview

Angular Router preloading: pass withPreloading(PreloadAllModules) to provideFileRouter(...), which accepts Angular router features, to preload lazy route chunks. The Analog docs show other router features there (withComponentInputBinding, withNavigationErrorHandler) and no preloading example. No link hover or viewport prefetch documented. (routing, PreloadAllModules)

Code example

provideFileRouter() takes Angular router features. withPreloading(PreloadAllModules) loads every lazy page chunk after the app starts.

// src/app/app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideFileRouter } from '@analogjs/router';
import { PreloadAllModules, withComponentInputBinding, withPreloading } from '@angular/router';

export const appConfig: ApplicationConfig = {
  providers: [
    provideFileRouter(withComponentInputBinding(), withPreloading(PreloadAllModules)),
    // …
  ],
};

Source: Analog: Routing, Angular: PreloadAllModules

Vike

1st-party2 ptsOverview

prefetchStaticAssets: 'hover' | 'viewport' | false, default 'hover', per page, with a per-link data-prefetch-static-assets override and a programmatic prefetch('/url'). Only static assets are prefetched; page data is not. (prefetchStaticAssets, prefetch)

Code example

prefetchStaticAssets sets when a link's page assets are prefetched. A link can override it with data-prefetch-static-assets, and prefetch() starts it from code.

// pages/+config.ts
export default { prefetchStaticAssets: 'viewport' }

// components/BookLink.tsx
import { prefetch } from 'vike/client/router'

export function BookLink({ id }: { id: string }) {
  return (
    <a href={`/book/${id}`} data-prefetch-static-assets="hover" onFocus={() => prefetch(`/book/${id}`)}>
      Details
    </a>
  )
}

Source: Vike: prefetchStaticAssets · Vike: prefetch()

RedwoodSDK

1st-party2 ptsOverview

With client-side navigation on, <link rel="x-prefetch" href="/about" /> makes RedwoodSDK fetch that route in the background after each navigation and store the response in the browser Cache API. Needs the onHydrated callback from initClientNavigation(). No hover or viewport trigger documented. (client-side-nav)

Code example

Turn on client navigation and pass onHydrated to initClient. Then render <link rel="x-prefetch"> for likely next routes. RedwoodSDK fetches each one after navigation and keeps it in the Cache API.

// src/client.tsx
import { initClient, initClientNavigation } from "rwsdk/client";

const { handleResponse, onHydrated } = initClientNavigation();
initClient({ handleResponse, onHydrated });
// src/app/pages/BlogListPage.tsx
import { link } from "@/shared/links";

export function BlogListPage({ posts }) {
  return posts.map((post) => {
    const href = link("/blog/:slug", { slug: post.slug });
    return (
      <article key={post.id}>
        <link rel="x-prefetch" href={href} />
        <a href={href}><h2>{post.title}</h2></a>
      </article>
    );
  });
}

Source: RedwoodSDK: Client Side Navigation

Remix 3

1st-party2 ptsOverview

<a href="/products/shirt" data-rmx-prefetch="intent"> or "viewport" loads the destination before navigation; prefetch() from remix/component does it from code. (component, interactivity)

Code example

Add data-rmx-prefetch to a link to load the destination on hover or focus (intent) or when it scrolls into view (viewport). prefetch() does the same from code.

// app/ui/book-link.tsx
import { prefetch } from "remix/component";
import type { Handle } from "remix/component";
import { routes } from "../routes.ts";

export function BookLink(handle: Handle<{ bookId: string; title: string }>) {
  return () => (
    <a href={routes.books.show.href({ bookId: handle.props.bookId })} data-rmx-prefetch="intent">
      {handle.props.title}
    </a>
  );
}

// elsewhere, from custom logic
prefetch(routes.books.show.href({ bookId: "dune" }));

Source: Remix: Interactivity, prefetch links before navigation

Void (React)

1st-party2 ptsOverview

<Link href="/dashboard" prefetch> from @void/react, with strategies 'hover' | 'click' | 'mount' | 'visible' (or an array), an app-wide prefetch.defaultStrategy on voidReact() (default false), hoverDelay (75 ms) and cacheFor, plus router.prefetch(). Prefetching runs the destination's loader, so page data is prefetched as well as code. Links skip it on data saver or 2G. (overview, pages adapters)

Code example

Add prefetch to <Link>. It loads the destination's code and runs its loader before the click. Strategies are hover, click, mount and visible, and prefetch.defaultStrategy on voidReact() turns it on for every link.

// pages/index.tsx
import { Link } from '@void/react'

export function BookLink({ id, title }: { id: string; title: string }) {
  return <Link href={`/${id}`} prefetch="hover">{title}</Link>
}

Source: Void: Prefetching

Void (Vue)

1st-party2 ptsOverview

<Link href="/dashboard" prefetch> from @void/vue, with strategies 'hover' | 'click' | 'mount' | 'visible' (or an array), an app-wide prefetch.defaultStrategy on voidVue() (default false), hoverDelay (75 ms) and cacheFor, plus router.prefetch(). Prefetching runs the destination's loader, so page data is prefetched as well as code. Links skip it on data saver or 2G. (overview, pages adapters)

Code example

Add prefetch to <Link>. It loads the destination's code and runs its loader before the click. Strategies are hover, click, mount and visible, and prefetch.defaultStrategy on voidVue() turns it on for every link.

<!-- components/BookLink.vue -->
<script setup lang="ts">
import { Link } from '@void/vue'
defineProps<{ id: string; title: string }>()
</script>

<template>
  <Link :href="`/${id}`" prefetch="hover">{{ title }}</Link>
</template>

Source: Void: Prefetching

Void (Svelte)

1st-party2 ptsOverview

<Link href="/dashboard" prefetch> from @void/svelte, with strategies 'hover' | 'click' | 'mount' | 'visible' (or an array), an app-wide prefetch.defaultStrategy on voidSvelte() (default false), hoverDelay (75 ms) and cacheFor, plus router.prefetch(). Prefetching runs the destination's loader, so page data is prefetched as well as code. Links skip it on data saver or 2G. (overview, pages adapters)

Code example

Add prefetch to <Link>. It loads the destination's code and runs its loader before the click. Strategies are hover, click, mount and visible, and prefetch.defaultStrategy on voidSvelte() turns it on for every link.

<!-- components/BookLink.svelte -->
<script lang="ts">
  import { Link } from '@void/svelte'
  let { id, title } = $props()
</script>

<Link href={`/${id}`} prefetch="hover">{title}</Link>

Source: Void: Prefetching

Void (Solid)

1st-party2 ptsOverview

<Link href="/dashboard" prefetch> from @void/solid, with strategies 'hover' | 'click' | 'mount' | 'visible' (or an array), an app-wide prefetch.defaultStrategy on voidSolid() (default false), hoverDelay (75 ms) and cacheFor, plus router.prefetch(). Prefetching runs the destination's loader, so page data is prefetched as well as code. Links skip it on data saver or 2G. (overview, pages adapters)

Code example

Add prefetch to <Link>. It loads the destination's code and runs its loader before the click. Strategies are hover, click, mount and visible, and prefetch.defaultStrategy on voidSolid() turns it on for every link.

// components/BookLink.tsx
import { Link } from '@void/solid'

export function BookLink(props: { id: string; title: string }) {
  return <Link href={`/${props.id}`} prefetch="hover">{props.title}</Link>
}

Source: Void: Prefetching

Gotchas

  • Prefetching spends bandwidth on routes the user may never visit; intent (hover/focus) is the conservative setting.