Bird
Raised Fist0
NextJSframework~8 mins

Full route cache in NextJS - Performance & Optimization

Choose your learning style10 modes available
Performance: Full route cache
HIGH IMPACT
Full route cache improves page load speed by serving pre-rendered pages instantly, reducing server work and network delays.
Serving a Next.js page quickly to users
NextJS
export async function getStaticProps() {
  const res = await fetch('https://api.example.com/data');
  const data = await res.json();
  return { props: { data }, revalidate: 3600 };
}

export default function Page({ data }) {
  return <div>{data.content}</div>;
}
Page is statically generated and cached, served instantly on requests, and revalidated periodically.
📈 Performance GainReduces server response time to near zero on cache hit; improves LCP by 300-500ms.
Serving a Next.js page quickly to users
NextJS
export async function getServerSideProps() {
  const res = await fetch('https://api.example.com/data');
  const data = await res.json();
  return { props: { data } };
}

export default function Page({ data }) {
  return <div>{data.content}</div>;
}
Page is rendered on every request causing slow server response and delayed page load.
📉 Performance CostBlocks rendering for 200-500ms depending on API speed; increases TTFB (Time to First Byte).
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Server-side rendering on every requestModerate (depends on data)Multiple reflows due to delayed contentHigh paint cost due to slow content arrival[X] Bad
Static generation with full route cacheMinimal (pre-rendered HTML)Single reflow on initial paintLow paint cost, fast content display[OK] Good
Rendering Pipeline
Full route cache serves pre-built HTML directly, skipping server rendering and data fetching on each request.
→Server Rendering
→Network
→First Paint
→Largest Contentful Paint
⚠️ BottleneckServer Rendering and Network latency
Core Web Vital Affected
LCP
Full route cache improves page load speed by serving pre-rendered pages instantly, reducing server work and network delays.
Optimization Tips
1Use static generation with caching to serve pages instantly.
2Avoid server-side rendering on every request for better LCP.
3Set appropriate revalidation times to keep cache fresh without slowing responses.
Performance Quiz - 3 Questions
Test your performance knowledge
How does full route caching affect Largest Contentful Paint (LCP) in Next.js?
AIt increases LCP by adding extra server processing.
BIt reduces LCP by serving pre-rendered pages instantly.
CIt has no effect on LCP.
DIt only affects input responsiveness, not LCP.
DevTools: Performance
How to check: Record a page load in DevTools Performance panel and look at the Time to First Byte and Largest Contentful Paint timings.
What to look for: Fast TTFB and early LCP indicate effective full route caching.

Practice

(1/5)
1. What does enabling full route cache in Next.js do for your page?
easy
A. It saves the entire page output to serve faster on next visits.
B. It disables all caching and forces server rendering every time.
C. It only caches API responses but not the page content.
D. It caches only images and static assets, not HTML.

Solution

  1. Step 1: Understand full route cache purpose

    Full route cache stores the whole rendered page output to speed up loading.
  2. Step 2: Compare options with this purpose

    Only "It saves the entire page output to serve faster on next visits." describes saving entire page output for faster serving.
  3. Final Answer:

    It saves the entire page output to serve faster on next visits. -> Option A
  4. Quick Check:

    Full route cache = saves full page output [OK]
Hint: Full route cache means caching the whole page output [OK]
Common Mistakes:
  • Thinking it only caches API data
  • Confusing with disabling cache
  • Assuming it caches only images
2. Which code snippet correctly enables full route cache in a Next.js page component?
easy
A. export const cache = 'no-cache';
B. export const revalidate = 0;
C. export const dynamic = 'force-static';
D. export const dynamic = 'force-dynamic';

Solution

  1. Step 1: Recall syntax for full route cache

    Next.js uses export const dynamic = 'force-static' to enable full route cache.
  2. Step 2: Check each option

    Only "export const dynamic = 'force-static';" matches the correct syntax for full route cache.
  3. Final Answer:

    export const dynamic = 'force-static'; -> Option C
  4. Quick Check:

    Full route cache syntax = dynamic = 'force-static' [OK]
Hint: Use dynamic = 'force-static' to enable full route cache [OK]
Common Mistakes:
  • Using 'force-dynamic' instead of 'force-static'
  • Confusing cache control with dynamic export
  • Setting revalidate to 0 disables caching differently
3. Given this Next.js page code, what will be the caching behavior?
export const dynamic = 'force-static';
export default function Page() {
  return <h1>Hello World</h1>;
}
medium
A. The page caches only API data but renders HTML dynamically.
B. The page is server rendered on every request without caching.
C. The page disables caching and reloads data on each visit.
D. The page is fully cached and served statically on all requests.

Solution

  1. Step 1: Analyze the dynamic export value

    The code sets dynamic = 'force-static', which enables full static caching.
  2. Step 2: Understand effect on page rendering

    This means the page HTML is cached fully and served statically on all requests.
  3. Final Answer:

    The page is fully cached and served statically on all requests. -> Option D
  4. Quick Check:

    dynamic = 'force-static' means full static cache [OK]
Hint: dynamic = 'force-static' means full static cache [OK]
Common Mistakes:
  • Thinking it disables caching
  • Assuming partial caching of API only
  • Confusing with dynamic rendering
4. Identify the error in this Next.js page that tries to enable full route cache:
export const dynamic = 'force-static'

export default function Page() {
  return <div>Cached Page</div>;
}
medium
A. Missing semicolon after dynamic export causes syntax error.
B. No error; code correctly enables full route cache.
C. Page component must be async to enable caching.
D. Using 'force-static' is invalid; should be 'force-dynamic'.

Solution

  1. Step 1: Check syntax correctness

    JavaScript allows omitting semicolons; no syntax error here.
  2. Step 2: Verify caching value and component

    'force-static' is valid to enable full route cache; component can be normal function.
  3. Final Answer:

    No error; code correctly enables full route cache. -> Option B
  4. Quick Check:

    Code syntax and caching value are correct [OK]
Hint: Semicolons optional; 'force-static' is valid caching value [OK]
Common Mistakes:
  • Assuming missing semicolon causes error
  • Confusing 'force-static' with 'force-dynamic'
  • Thinking component must be async
5. You want to optimize a mostly static blog page with some dynamic widgets. Which approach best uses full route cache in Next.js?
hard
A. Set export const dynamic = 'force-static' and load widgets client-side only.
B. Use dynamic = 'force-dynamic' to cache the whole page including widgets.
C. Disable caching and fetch all data server-side on every request.
D. Use revalidate = 0 to cache page but update widgets dynamically.

Solution

  1. Step 1: Understand full route cache use case

    Full route cache works best for mostly static pages to serve fast.
  2. Step 2: Handle dynamic widgets separately

    Loading widgets client-side keeps page static cache intact while showing dynamic content.
  3. Step 3: Evaluate options

    Set export const dynamic = 'force-static' and load widgets client-side only. matches this approach; others either disable caching or cache dynamic parts incorrectly.
  4. Final Answer:

    Set export const dynamic = 'force-static' and load widgets client-side only. -> Option A
  5. Quick Check:

    Static page + client widgets = dynamic = 'force-static' [OK]
Hint: Cache static page, load dynamic parts client-side [OK]
Common Mistakes:
  • Caching dynamic widgets server-side causing stale data
  • Disabling cache unnecessarily
  • Using force-dynamic which disables full route cache
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