Next.jsMedium
How does prefetching work with the Link component?
When a <Link> enters the viewport in production, Next.js downloads the destination route's data in the background so the click renders instantly. How much is prefetched depends on the prefetch prop, the route's static or dynamic parts and, since Next.js 16.3, Partial Prefetching.
Default behavior (prefetch="auto")
- Static routes: the whole route payload is prefetched.
- Dynamic routes without Partial Prefetching: only the part down to the nearest
loading.tsxboundary is prefetched, so the loading state shows instantly and the rest streams after the click. - With Partial Prefetching (
partialPrefetching: true, default for new 16.4 apps): the router prefetches each route's App Shell: its static and cached content plus<Suspense>fallbacks.
Other values
prefetch={true}: prefetch more. With Partial Prefetching, the server renders the route again with the link's URL resolved (params,searchParams), so cached content for that exact URL arrives before the click. This costs a server invocation per link.prefetch={false}: never prefetch, not even on hover.
Next.js 16 improvements
- Layout deduplication: a shared layout is downloaded once even when many links point to routes under it.
- Incremental prefetching: only parts missing from the client cache are requested.
- Prefetch inlining: small segment responses are bundled into one request automatically (16.3).
Controls on the destination
- Route segment config
export const prefetch = 'force-disabled'stops prefetching a segment. await prefetch()andawait navigation()fromnext/cachedefer expensive subtrees to later navigation stages.
Good to know
Prefetching is disabled in next dev, so test with next build && next start. Use router.prefetch(href) for manual prefetches.
Code example
tsx
1// app/components/product-links.tsx2import Link from "next/link";34export function ProductLinks({ ids }: { ids: string[] }) {5 return (6 <ul>7 {ids.map((id) => (8 <li key={id}>9 {/* Default: App Shell prefetched when visible */}10 <Link href={`/products/${id}`}>Product {id}</Link>11 </li>12 ))}1314 {/* Likely next step: also prefetch cached content for this exact URL */}15 <li>16 <Link href="/search?q=shoes" prefetch={true}>Popular: shoes</Link>17 </li>1819 {/* Rarely visited, expensive page: skip prefetching */}20 <li>21 <Link href="/admin/reports" prefetch={false}>Reports</Link>22 </li>23 </ul>24 );25}2627// next.config.ts28// const nextConfig = { cacheComponents: true, partialPrefetching: true };
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.