0
0
NextJSframework~20 mins

Route prefetching behavior in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Route Prefetching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Next.js Link with prefetch enabled is rendered?

Consider a Next.js app with a <Link> component that has prefetch enabled (default behavior). What does Next.js do when this component appears on the page?

NextJS
<Link href="/about">About</Link>
ANext.js prefetches only the CSS for the /about page but not the JavaScript.
BNext.js waits until the user clicks the link before fetching the /about page resources.
CNext.js disables prefetching if the link is outside the viewport.
DNext.js automatically fetches the JavaScript and data for the /about page in the background after the page loads.
Attempts:
2 left
💡 Hint

Think about how Next.js improves navigation speed by loading pages early.

state_output
intermediate
2:00remaining
What is the effect of disabling prefetch on a Next.js Link?

Given this code snippet, what will be the user experience difference compared to default prefetch behavior?

<Link href="/contact" prefetch={false}>Contact</Link>
AThe link will not navigate to /contact at all because prefetch is false.
BThe /contact page resources are fetched immediately when the page loads, same as default.
CThe /contact page resources are only fetched when the user clicks the link, causing a slight delay on navigation.
DThe /contact page resources are fetched only when the link is hovered by the mouse.
Attempts:
2 left
💡 Hint

Disabling prefetch means Next.js won't load the page early.

📝 Syntax
advanced
2:00remaining
Which code snippet correctly disables prefetching for a Next.js Link?

Choose the correct way to disable prefetching on a Next.js Link component.

A<Link href="/blog" prefetch="false">Blog</Link>
B<Link href="/blog" prefetch={false}>Blog</Link>
C<Link href="/blog" prefetch={0}>Blog</Link>
D<Link href="/blog" prefetch={null}>Blog</Link>
Attempts:
2 left
💡 Hint

Remember that prefetch expects a boolean value.

🔧 Debug
advanced
2:00remaining
Why does prefetch not work on a dynamic route Link in Next.js?

Given a dynamic route /posts/[id] and this Link:

<Link href="/posts/[id]" as="/posts/123">Post 123</Link>

Why might Next.js not prefetch this page?

ANext.js cannot prefetch dynamic routes without explicit <code>href</code> parameters matching the dynamic segments.
BPrefetching is disabled by default on all dynamic routes.
CThe <code>as</code> prop disables prefetching automatically.
DPrefetching only works on static HTML pages, not on dynamic routes.
Attempts:
2 left
💡 Hint

Think about how Next.js needs to know the exact path to prefetch.

🧠 Conceptual
expert
2:00remaining
When does Next.js trigger route prefetching for Link components?

Which of the following best describes when Next.js triggers prefetching for a Link component?

ANext.js prefetches routes for Link components that are visible in the viewport after the page load event.
BNext.js prefetches routes only when the Link component is focused via keyboard navigation.
CNext.js prefetches routes only when the user hovers over the Link component.
DNext.js prefetches all Link routes on the page immediately during server-side rendering.
Attempts:
2 left
💡 Hint

Consider how Next.js balances performance and user experience by prefetching only visible links.