0
0
NextJSframework~20 mins

Router cache on client in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Router Cache Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Next.js cache pages on the client?

Consider a Next.js app using the App Router. When you navigate between pages, how does Next.js handle caching on the client side?

ANext.js caches the JavaScript and JSON data for pages in memory, enabling fast client-side transitions without full reloads.
BNext.js caches the entire HTML of each page in the browser's local storage for instant reloads.
CNext.js disables caching on the client to always fetch fresh data from the server on navigation.
DNext.js caches only CSS files on the client, but reloads page data every time.
Attempts:
2 left
💡 Hint

Think about how client-side navigation avoids full page reloads.

state_output
intermediate
2:00remaining
What happens to client cache after a server action updates data?

In a Next.js app using server actions and the App Router, you update data on the server. What happens to the cached page data on the client after this update?

AThe client cache is cleared immediately and the page reloads automatically.
BThe client cache remains unchanged until the user manually refreshes the page.
CThe client cache is automatically invalidated and refetched on next navigation to show updated data.
DThe client cache duplicates the old and new data causing inconsistent UI.
Attempts:
2 left
💡 Hint

Think about how Next.js keeps UI data fresh after server changes.

📝 Syntax
advanced
2:00remaining
Identify the correct way to prefetch a route in Next.js App Router

Which code snippet correctly prefetches a route to warm the client cache before navigation?

NextJS
import { useRouter } from 'next/navigation';

export default function PrefetchExample() {
  const router = useRouter();

  function prefetchPage() {
    // Which line correctly prefetches '/dashboard'?
  }

  return <button onClick={prefetchPage}>Prefetch Dashboard</button>;
}
Arouter.prefetchPage('/dashboard');
Brouter.prefetch('/dashboard');
Crouter.load('/dashboard');
Drouter.cache('/dashboard');
Attempts:
2 left
💡 Hint

Check the official Next.js navigation API for prefetching.

🔧 Debug
advanced
2:00remaining
Why does client cache not update after navigation in this Next.js code?

Given this Next.js App Router code snippet, why does the client cache not update after navigating to '/profile'?

NextJS
import Link from 'next/link';

export default function Nav() {
  return <Link href="/profile" prefetch={false}>Go to Profile</Link>;
}
ABecause the <code>href</code> value is incorrect and causes navigation failure.
BBecause the <code>Link</code> component requires an explicit <code>cache</code> prop to update cache.
CBecause Next.js disables client cache by default for all links.
DBecause <code>prefetch</code> is set to false, Next.js does not cache the page data before navigation.
Attempts:
2 left
💡 Hint

Look at the prefetch prop and what it controls.

🧠 Conceptual
expert
3:00remaining
How does Next.js App Router handle cache consistency with server components and client navigation?

Explain how Next.js App Router ensures cache consistency between server components and client-side navigation when data changes frequently.

ANext.js uses a cache invalidation system that tracks data dependencies and refetches server components on navigation or mutations to keep client cache fresh.
BNext.js relies on browser cache headers only and does not manage cache consistency internally.
CNext.js duplicates server component data in local storage and syncs it periodically with the server.
DNext.js disables caching for server components and always fetches fresh data on every client navigation.
Attempts:
2 left
💡 Hint

Think about how Next.js manages data freshness with server components and client cache.