Route prefetching helps your app load pages faster by getting them ready before you click. It makes navigation smooth and quick.
Route prefetching behavior in NextJS
import Link from 'next/link'; <Link href="/about" prefetch={true}>About</Link>
The prefetch prop on Link controls if Next.js preloads the page.
By default, Next.js prefetches pages in the viewport when using next/link.
<Link href="/contact" prefetch={false}>Contact</Link>
<Link href="/blog">Blog</Link>import { useEffect } from 'react'; import { useRouter } from 'next/router'; const Component = () => { const router = useRouter(); useEffect(() => { router.prefetch('/dashboard'); }, [router]); return <div>Dashboard Prefetch Example</div>; };
This component shows three links with different prefetch behaviors. The About page is prefetched manually on load, Contact disables prefetch, and Blog uses default prefetching.
import Link from 'next/link'; import { useRouter } from 'next/router'; import { useEffect } from 'react'; export default function Home() { const router = useRouter(); useEffect(() => { // Manually prefetch the /about page router.prefetch('/about'); }, [router]); return ( <main> <h1>Welcome to Home</h1> <nav> <ul> <li><Link href="/about">About (prefetched manually)</Link></li> <li><Link href="/contact" prefetch={false}>Contact (no prefetch)</Link></li> <li><Link href="/blog">Blog (default prefetch)</Link></li> </ul> </nav> </main> ); }
Prefetching only works in production builds, not in development mode.
Prefetching uses idle browser time to avoid slowing down the main work.
Too much prefetching can waste bandwidth, so use it wisely.
Route prefetching loads pages in the background to speed up navigation.
You can control prefetching with the prefetch prop on Link or manually with router.prefetch().
Use prefetching to improve user experience but avoid overusing it to save bandwidth.