PerformanceArchitecture
SSGFeb 23, 2026, 05:43:40 PM

Caching Strategies

Performance is often just a matter of 'not doing the work'. Learn how browsers, CDNs, and frameworks coordinate to store data as close to the user as possible.

Rendering EnvServer Runtime

Strategy Details

Next.js handles most of this automatically. By using static rendering (SSG/ISR), your application is globally cached by default.

Hydration Logic

Pre-rendered HTML is sent to the client, then React 'hydrates' it to enable full interactivity.

The Multi-Level Cache

Speed isn't just about rendering; it's about ensuring data never has to travel to the server if someone else has already seen it.

Data Cache

Origin Server

Database & Redis caching. Next.js "fetch()" cache persists here.

Server-Cache-Control
Edge Cache

Global CDN (Edge)

Cached HTML/Images at locations nearest to users (e.g., Tokyo, NYC).

Edge-Cache-Control
Local Cache

Browser Memory

Assets stored locally on your device for instant repeat visits.

Cache-Control

Global CDN Data

For SSG and ISR pages. Data is Global—the same for every user on earth. This is cached on the Edge Network so it never hits your server.

Safe for CDN (Cache-Control: public)

Personalized Data

Data that belongs to a specific user (Account details, carts). Must Bypass CDN to prevent data leaking between users.

Dynamic Only (Cache-Control: private)

Developer Tools Deep Dive

How to verify your caching strategy using the browser's Network tab.

Inspection: Network Headers

Open your browser DevTools (F12) $\rightarrow$ Network Tab $\rightarrow$ Click a Request $\rightarrow$ Response Headers.

Vercel Note: Next.js automatically sets these headers based on your page configuration (SSG/ISR/SSR).

Response Headers/_next/static/css/main.css
Cache-Control:public, max-age=31536000, immutable
ETag:W/"5d-5f3e2"
X-Vercel-Cache:HIT
Age:45210

Architecture Impact

CSS and JS bundles use "immutable" hashes. They stay in the browser cache forever until the filename changes.

The Framework Guarantee

When you use Static Rendering (SSG), Next.js automatically generates the ideal Cache-Control headers for you. You don't need to manually configure CDNs—the framework ensures that your global assets are distributed globally, while your private routes remain private.

Auto-Purge

CDN caches are invalidated automatically on new deployments.

Stale-While

ISR allows the CDN to serve old data while fetching the new update.

Hashed Assets

Images and CSS are hashed, allowing infinite browser caching.