0
0
NextJSframework~8 mins

Fetch caching behavior in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Fetch caching behavior
MEDIUM IMPACT
This affects how quickly data loads on the page and how often the browser or server fetches data again.
Fetching data on page load with caching
NextJS
const res = await fetch('/api/data', { cache: 'force-cache' });
const data = await res.json();
Uses cached response if available, reducing network requests and speeding up load.
📈 Performance Gainreduces network requests, improves LCP by loading data faster
Fetching data on page load with caching
NextJS
const res = await fetch('/api/data', { cache: 'no-store' });
const data = await res.json();
This disables caching, causing a new network request on every page load, slowing down load time.
📉 Performance Costblocks rendering for every request, increases network latency
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Fetch with no-store cacheMinimal0Low[X] Bad
Fetch with force-cacheMinimal0Low[OK] Good
Rendering Pipeline
Fetch caching affects the network request stage before rendering. Cached data can skip network delays, speeding up style calculation and layout.
Network Request
Style Calculation
Layout
Paint
⚠️ BottleneckNetwork Request
Core Web Vital Affected
LCP
This affects how quickly data loads on the page and how often the browser or server fetches data again.
Optimization Tips
1Use 'force-cache' or default caching to speed up repeated fetches.
2Avoid 'no-store' unless fresh data is critical every time.
3Check network tab to confirm caching behavior and reduce redundant requests.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main benefit of using fetch caching in Next.js?
AReduces network requests and speeds up page load
BIncreases the number of network requests
CBlocks rendering until all data is fetched
DDisables browser cache completely
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and observe if fetch requests are served from cache (status 200 from disk cache or 304).
What to look for: Look for fewer network requests and faster response times indicating effective caching.