Consider a Next.js Server Component that fetches data from an API using fetch with cache: 'force-cache'. What happens when the component is rendered multiple times within 10 seconds?
export default async function Page() { const res = await fetch('https://api.example.com/data', { cache: 'force-cache' }); const data = await res.json(); return <pre>{JSON.stringify(data)}</pre>; }
Think about how cache: 'force-cache' enables server-side caching.
Using cache: 'force-cache' tells Next.js to cache the fetched data on the server indefinitely. Repeated renders use the cached data instead of refetching.
Given this Next.js Server Component code snippet, what will the user see immediately after the first render if the cache is stale?
export default async function Page() { const res = await fetch('https://api.example.com/data', { next: { revalidate: 30 } }); const data = await res.json(); return <pre>{JSON.stringify(data)}</pre>; }
Recall how stale-while-revalidate works in caching strategies.
With { next: { revalidate: 30 } }, Next.js serves cached data immediately even if stale, then fetches fresh data in the background to update the cache for future requests.
Look at this Next.js Server Component fetching data with revalidate: 5. The data does not update after 5 seconds as expected. What is the likely cause?
export default async function Page() { const res = await fetch('https://api.example.com/data', { next: { revalidate: 5 } }); const data = await res.json(); return <pre>{JSON.stringify(data)}</pre>; }
Consider external factors affecting data freshness beyond Next.js settings.
If a CDN or proxy caches the API response, Next.js fetches stale data despite revalidate. The cache must be cleared or bypassed at the API level.
Which statement best describes data caching behavior when fetching data inside a Next.js Client Component?
Think about where Client Components run and how caching works there.
Client Components run in the browser and do not use Next.js server caching. Fetch requests run fresh unless the developer implements caching manually.
Choose the correct fetch option syntax to enable ISR with a 60-second revalidation in a Next.js Server Component.
Check the official Next.js fetch options for ISR.
The correct syntax to enable ISR is to pass revalidate inside the next option object: { next: { revalidate: 60 } }.