Bird
Raised Fist0
NextJSframework~20 mins

Why caching is central to Next.js - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Next.js Caching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does Next.js use caching for server components?
Next.js uses caching for server components mainly to:
AStore user passwords securely on the server
BAutomatically update the UI without developer input
CReduce repeated data fetching and speed up page rendering
DEnable client-side routing without page reloads
Attempts:
2 left
💡 Hint
Think about how caching helps avoid doing the same work multiple times.
❓ component_behavior
intermediate
2:00remaining
What happens when cached data in Next.js expires?
In Next.js, when cached data for a page expires, the framework will:
ADelete the page and show a 404 error
BForce the user to reload the browser manually
CServe stale data indefinitely without updating
DFetch fresh data and update the cache before serving the page
Attempts:
2 left
💡 Hint
Consider how caching systems keep data fresh.
📝 Syntax
advanced
2:30remaining
Which Next.js code snippet correctly enables caching for a server component?
Select the code snippet that properly uses Next.js caching for a server component fetching data.
NextJS
import { cache } from 'react';

const fetchData = cache(async () => {
  const res = await fetch('https://api.example.com/data');
  return res.json();
});

export default async function Page() {
  const data = await fetchData();
  return <div>{data.message}</div>;
}
ACalls fetch() directly inside the component without caching
BUses the cache() wrapper around the async fetch function to memoize results
CCaches data by storing it in a global variable manually
DUses useState hook to cache data on the client side
Attempts:
2 left
💡 Hint
Look for the official React cache() function usage.
🔧 Debug
advanced
2:30remaining
Why does this Next.js server component fetch data on every request despite caching?
Given this code, why is data fetched every time instead of cached? import { cache } from 'react'; async function getData() { return await fetch('https://api.example.com/data').then(res => res.json()); } const cachedGetData = cache(getData); export default async function Page() { const data = await getData(); return
{data.title}
; }
AThe component calls getData() directly instead of cachedGetData(), so caching is bypassed
BThe cache() function is used incorrectly and does not memoize async functions
CNext.js disables caching by default in server components
DThe fetch URL is dynamic and prevents caching
Attempts:
2 left
💡 Hint
Check which function is actually called inside the component.
❓ lifecycle
expert
3:00remaining
How does Next.js caching interact with Incremental Static Regeneration (ISR)?
In Next.js, when using ISR with a revalidate time, caching works by:
AServing a cached static page until the revalidate time expires, then regenerating the page in the background
BRegenerating the page on every request without caching
CDisabling caching completely to always show fresh data
DServing stale pages indefinitely without regeneration
Attempts:
2 left
💡 Hint
Think about how ISR balances caching and freshness.

Practice

(1/5)
1. Why is caching important in Next.js for website performance?
easy
A. It stores parts of the website to load pages faster.
B. It deletes all data after every page load.
C. It slows down the website to save energy.
D. It disables JavaScript on the page.

Solution

  1. Step 1: Understand caching purpose

    Caching saves website parts so they don't need to be rebuilt every time.
  2. Step 2: Connect caching to Next.js performance

    Next.js uses caching to serve pages quickly by reusing saved content.
  3. Final Answer:

    It stores parts of the website to load pages faster. -> Option A
  4. Quick Check:

    Caching = Faster page loads [OK]
Hint: Caching means saving parts to speed up loading [OK]
Common Mistakes:
  • Thinking caching deletes data after load
  • Believing caching slows down the site
  • Confusing caching with disabling JavaScript
2. Which Next.js feature controls how often cached pages update?
easy
A. revalidate
B. getStaticProps
C. useEffect
D. getServerSideProps

Solution

  1. Step 1: Identify caching update control

    Next.js uses the revalidate property to set cache refresh timing.
  2. Step 2: Differentiate from other features

    getStaticProps fetches data at build time, useEffect runs on client, getServerSideProps fetches on every request.
  3. Final Answer:

    revalidate -> Option A
  4. Quick Check:

    Cache update timing = revalidate [OK]
Hint: Look for 'revalidate' to set cache refresh time [OK]
Common Mistakes:
  • Confusing getStaticProps with cache timing
  • Using useEffect for server caching
  • Thinking getServerSideProps controls caching
3. What will happen if you set revalidate: 10 in getStaticProps?
medium
A. The page updates on every request.
B. The page updates every 10 seconds after first load.
C. The page never updates after build.
D. The page updates every 10 minutes.

Solution

  1. Step 1: Understand revalidate value meaning

    Setting revalidate: 10 means Next.js will refresh the cached page every 10 seconds.
  2. Step 2: Compare with other options

    It does not update on every request, never after build, nor every 10 minutes.
  3. Final Answer:

    The page updates every 10 seconds after first load. -> Option B
  4. Quick Check:

    revalidate: 10 means 10 seconds refresh [OK]
Hint: revalidate number = seconds between cache refresh [OK]
Common Mistakes:
  • Thinking revalidate is minutes, not seconds
  • Believing page never updates with revalidate
  • Confusing revalidate with server-side rendering
4. You set revalidate: '10' (string) instead of 10 (number). What happens?
medium
A. Next.js updates the page every 10 minutes.
B. Next.js treats it as 10 seconds anyway.
C. Next.js ignores revalidate and never updates the page.
D. Next.js throws a type error and fails to build.

Solution

  1. Step 1: Check revalidate type requirement

    Next.js expects revalidate as a number, not a string.
  2. Step 2: Understand error on wrong type

    Passing a string causes a type error and build failure.
  3. Final Answer:

    Next.js throws a type error and fails to build. -> Option D
  4. Quick Check:

    revalidate must be number, string causes error [OK]
Hint: Use number type for revalidate, not string [OK]
Common Mistakes:
  • Passing string instead of number for revalidate
  • Assuming Next.js auto-converts string to number
  • Ignoring build errors caused by wrong types
5. You want a page to show fresh data but still load fast. Which caching strategy fits best in Next.js?
hard
A. Disable caching completely.
B. Use getServerSideProps to fetch data on every request.
C. Set revalidate to a low number like 5 seconds.
D. Set revalidate to a very high number like 86400 seconds.

Solution

  1. Step 1: Balance freshness and speed

    Low revalidate means data updates often but still uses cache for speed.
  2. Step 2: Compare other options

    getServerSideProps fetches every time but is slower; very high revalidate delays updates; disabling cache hurts speed.
  3. Final Answer:

    Set revalidate to a low number like 5 seconds. -> Option C
  4. Quick Check:

    Low revalidate = fresh + fast [OK]
Hint: Low revalidate balances fresh data and speed [OK]
Common Mistakes:
  • Choosing getServerSideProps for speed
  • Setting revalidate too high losing freshness
  • Disabling cache hurting performance
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard