0
0
NextJSframework~8 mins

Why caching is central to Next.js - Performance Evidence

Choose your learning style9 modes available
Performance: Why caching is central to Next.js
HIGH IMPACT
Caching in Next.js affects page load speed and reduces server response time by reusing previously generated content.
Serving pages quickly in Next.js
NextJS
export async function getStaticProps() {
  const data = await fetch('https://api.example.com/data');
  const json = await data.json();
  return { props: { json }, revalidate: 60 };
}

// Static generation with incremental static regeneration caches page for 60 seconds
Page is prebuilt and cached, served instantly, and only regenerated periodically.
📈 Performance GainReduces server response time to under 50ms, lowers CPU load, improves LCP
Serving pages quickly in Next.js
NextJS
export async function getServerSideProps() {
  const data = await fetch('https://api.example.com/data');
  const json = await data.json();
  return { props: { json } };
}

// This runs on every request, no caching
Fetching data and rendering on every request causes slow response and high server load.
📉 Performance CostBlocks rendering for 200-500ms per request, increases server CPU usage
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Server-side rendering on every requestN/AN/AHigh due to slow server response[X] Bad
Static generation with cachingN/AN/ALow due to fast server response[OK] Good
Rendering Pipeline
Next.js caching avoids repeated server-side rendering by serving prebuilt HTML and JSON. This skips expensive data fetching and rendering during the critical rendering path.
Server Rendering
Network
Browser Rendering
⚠️ BottleneckServer Rendering when no cache is used
Core Web Vital Affected
LCP
Caching in Next.js affects page load speed and reduces server response time by reusing previously generated content.
Optimization Tips
1Use static generation with caching to speed up page loads.
2Avoid server-side rendering on every request for better performance.
3Set revalidate times to balance freshness and speed.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of caching pages in Next.js?
ALarger JavaScript bundles
BMore frequent server rendering
CFaster page load by serving prebuilt content
DIncreased network requests
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, check response time and if HTML is served from cache or freshly generated
What to look for: Look for fast initial HTML response times under 100ms indicating cached content; slow times indicate no caching