Consider a Next.js app using the App Router. When you navigate between pages, how does Next.js handle caching on the client side?
Think about how client-side navigation avoids full page reloads.
Next.js caches JavaScript bundles and JSON data for pages in memory on the client. This allows fast navigation between pages without reloading the entire page or fetching all data again.
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?
Think about how Next.js keeps UI data fresh after server changes.
Next.js automatically invalidates cached data related to the updated server action. On next navigation or re-render, it refetches fresh data to keep the UI consistent.
Which code snippet correctly prefetches a route to warm the client cache before navigation?
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>; }
Check the official Next.js navigation API for prefetching.
The router.prefetch() method is the correct way to prefetch a route in Next.js App Router, warming the client cache for faster navigation.
Given this Next.js App Router code snippet, why does the client cache not update after navigating to '/profile'?
import Link from 'next/link'; export default function Nav() { return <Link href="/profile" prefetch={false}>Go to Profile</Link>; }
Look at the prefetch prop and what it controls.
Setting prefetch={false} disables automatic prefetching and caching of the linked page, so the client cache is not warmed before navigation.
Explain how Next.js App Router ensures cache consistency between server components and client-side navigation when data changes frequently.
Think about how Next.js manages data freshness with server components and client cache.
Next.js tracks which data each server component depends on. When data changes, it invalidates related cache entries so client navigation triggers fresh fetches, ensuring UI consistency.