0
0
NextJSframework~20 mins

Opting out of caching in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Caching Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when opting out of caching in a Next.js Server Component?

Consider a Next.js Server Component that fetches data but opts out of caching using export const revalidate = 0;. What happens when you refresh the page multiple times?

NextJS
export const revalidate = 0;

export default async function Page() {
  const time = new Date().toISOString();
  return <p>Current time: {time}</p>;
}
AThe time updates on every refresh because caching is disabled.
BThe time stays the same on every refresh because data is cached indefinitely.
CThe page throws an error because revalidate cannot be zero.
DThe time updates only once per minute due to default caching.
Attempts:
2 left
💡 Hint

Think about what setting revalidate = 0 means for data fetching in Next.js.

📝 Syntax
intermediate
1:30remaining
Which code snippet correctly opts out of caching in Next.js 14+?

Choose the correct way to disable caching for a Next.js Server Component.

Aexport const cache = false;
Bexport const noCache = true;
Cexport const revalidate = false;
Dexport const revalidate = 0;
Attempts:
2 left
💡 Hint

Look for the official Next.js export that controls cache revalidation timing.

🔧 Debug
advanced
2:30remaining
Why does this Next.js page still cache data despite setting revalidate to 0?

Review the code below. The developer expects no caching, but the page shows stale data on refresh. What is the likely cause?

NextJS
export const revalidate = 0;

export default async function Page() {
  const data = await fetch('https://api.example.com/data', { cache: 'force-cache' }).then(res => res.json());
  return <p>{data.message}</p>;
}
AThe fetch uses <code>cache: 'force-cache'</code> which overrides revalidate and caches the response.
BThe revalidate export must be a function, not a number.
CThe API endpoint is down, causing stale data to appear.
DNext.js ignores revalidate when fetch is used inside Server Components.
Attempts:
2 left
💡 Hint

Check the fetch options and how they interact with Next.js caching.

🧠 Conceptual
advanced
2:00remaining
What is the effect of export const dynamic = 'force-dynamic' in Next.js?

In Next.js 14+, what does setting export const dynamic = 'force-dynamic' do for a page or layout?

AIt caches the page for 10 seconds before revalidating.
BIt forces the page to be rendered dynamically on every request, disabling static caching.
CIt disables the page from rendering on the server and forces client-side rendering.
DIt forces the page to be statically generated at build time.
Attempts:
2 left
💡 Hint

Consider how dynamic rendering differs from static generation.

state_output
expert
3:00remaining
What is the rendered output of this Next.js Server Component with caching disabled and a client component inside?

Analyze the code below. What will the user see when the page loads and after clicking the button?

NextJS
export const revalidate = 0;

'use client';
import { useState } from 'react';

function ClientCounter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
}

export default function Page() {
  const time = new Date().toISOString();
  return (
    <>
      <p>Server time: {time}</p>
      <ClientCounter />
    </>
  );
}
AThe server time never updates on refresh, and the button does not increment the count.
BThe page shows an error because client components cannot be used inside server components with revalidate set to 0.
CThe page shows the current server time that updates on every refresh, and the button increments count on clicks without refreshing the time.
DThe button increments count but the server time also updates on every click.
Attempts:
2 left
💡 Hint

Think about how server and client components behave together and how caching affects server-rendered data.