Next.js Rendering Strategies and Caching
Classic interview questions: "When do SSR, SSG, ISR and streaming each fit?" and "Why isn't my data updating?" (a caching problem).
Core concepts
| Strategy | When HTML is generated | Good for |
|---|---|---|
| Static rendering (SSG) | At build time | Docs, marketing pages |
| ISR / time-based revalidation | Generated at build time, regenerated in the background once stale | Lists that rarely change |
| Dynamic rendering (SSR) | On every request | Pages that depend on the user's identity or real-time data |
| Streaming | Send the shell first, then stream each part in via Suspense as its data is ready | Pages with some slow queries |
| PPR / Cache Components | A static shell + dynamic holes in the same page (available via Cache Components from Next.js 16) | Mostly static pages with dynamic parts |
How it works
How the caching defaults evolved (frequently asked)
- Next.js 14 and earlier:
fetchwas cached by default, and many people hit "my data doesn't update". - Next.js 15:
fetchrequests andGETRoute Handlers are no longer cached by default; caching became opt-in. - Next.js 16: introduces Cache Components. After enabling
cacheComponents: trueinnext.config.ts, you explicitly mark cacheable functions/components with the"use cache"directive, together withcacheLife(cache duration) andcacheTag/revalidateTag(invalidation by tag).
The core idea: dynamic by default, caching must be declared explicitly, which makes behavior more predictable.
Streaming and Suspense
tsx
export default function Page() {
return (
<>
<Header /> {/* sent immediately */}
<Suspense fallback={<Skeleton />}>
<SlowStats /> {/* streamed in once its data is ready */}
</Suspense>
</>
)
}loading.tsx simply wraps the whole route segment in a Suspense boundary automatically.
In practice
tsx
// With Cache Components enabled: a cacheable data function
import { cacheLife, cacheTag } from 'next/cache'
export async function getRuleSet(customerId: string) {
'use cache'
cacheLife('hours')
cacheTag(`rules-${customerId}`)
return fetch(`${process.env.API_URL}/customers/${customerId}/rules`).then(r => r.json())
}
// After rules are updated: invalidate by tag in a Server Action (see the to-be-verified note for the exact API)Recommendation for admin-style apps: render highly real-time, permissioned pages such as the task list and review console dynamically; explicitly cache only data that rarely changes, such as customer rules and dictionaries.
Common pitfalls
- Confusing the cache layers: browser HTTP cache, client router cache, server data cache and CDN are all independent. Check them one layer at a time when debugging.
- Reading cookies / headers inside a cached function: once user-specific data is cached, one user may see another's data.
- Following old tutorials: many articles online are based on Next.js 13/14 default caching behavior, which no longer applies.
Common interview questions
- When do SSR, SSG, ISR and streaming each fit?
- What did Next.js 15 / 16 change about default caching behavior, and why?
- How do
"use cache"andrevalidateTagwork together? - What role does Suspense play in server rendering?
To be verified / may go stale
- For the signature of
revalidateTagin Next.js 16 and how to use the new invalidation APIs such asupdateTag/refresh, follow the current official "Caching and Revalidating" docs. - The Cache Components APIs are still evolving quickly.
Sources
- Next.js Blog: Next.js 16 — Cache Components, the
cacheComponentsconfig - Next.js Blog: Next.js 15 (2024-10) — fetch and GET Route Handlers not cached by default
- Next.js Docs: Caching and Revalidating
- Next.js Docs: Linking and Navigating / Streaming
- React Docs: Suspense
