Ankit KanojiyaIntermediate

Evergreen guide by Ankit Kanojiya · Intermediate · Frontend

Next.js Rendering: SSR, SSG, ISR and Server Components

How Next.js decides when a page is rendered, what SSR, SSG, ISR and Server Components actually mean, and how Cache Components change the picture in Next.js 16.

If you have built a React app with Vite or Create React App, the browser got an almost empty HTML file plus a big JavaScript bundle, and React built the page on the user's device. That works, but it has three costs: the user sees nothing until the JS downloads and runs, search engines have to execute your JS to see content, and every data fetch starts only after the bundle has loaded.

Next.js exists mostly to give you other options for when and where a page gets rendered. The terms SSR, SSG, ISR and Server Components are all answers to that one question. Interviewers ask about them constantly because the answers show whether you understand the trade-offs, not just the acronyms.

The four options

Server-Side Rendering (SSR) renders the page on the server for every request. The user gets full HTML immediately, then React "hydrates" it, attaching event handlers so it becomes interactive. Fresh data on every hit, but every hit costs a server render and the page cannot be served from a CDN as-is.

Static Site Generation (SSG) renders the page once at build time. The output is plain HTML and a serialised React payload sitting on a CDN. Fastest possible delivery and nearly free to serve, but the content is only as fresh as your last deploy.

Incremental Static Regeneration (ISR) is SSG with an expiry. You set a revalidation time, say 60 seconds. The first request after the timer expires still gets the old cached page, but triggers a rebuild in the background; the next visitor gets the new one. You get CDN speed with content that is at most a minute stale, without redeploying. ISR also handles pages you did not build at all: a blog post nobody linked at build time is rendered on first request and cached from then on.

React Server Components (RSC) are a different axis. The three above decide when a page is rendered. Server Components decide which parts of the component tree run on the server only. A Server Component executes on the server, can read a database or the filesystem directly, and sends the browser its rendered output rather than its code. It never hydrates, never ships its JavaScript, and cannot use useState or onClick. Client Components, marked with "use client" at the top of the file, are the ordinary React components you know, and they can be nested inside Server Components.

In the App Router every component is a Server Component unless you say otherwise. Beginners trip on this constantly: they add useState to a page file and get a build error.

How Next.js actually decides

In the App Router (Next.js 13 onwards), you do not pick SSR or SSG with a function name the way the old getServerSideProps / getStaticProps pair worked. Next.js looks at what your route does and decides:

  • If a route reads nothing that depends on the incoming request, it is prerendered at build time. That is SSG.
  • If it reads cookies(), headers(), searchParams, or a dynamic params value that was not listed in generateStaticParams, it has to be rendered per request. That is SSR; the docs call it dynamic rendering.
  • If it exports revalidate = 60 (or a fetch call sets next: { revalidate: 60 }), the prerendered page is regenerated on that schedule. That is ISR.

Here is a page that gets statically rendered and regenerated every hour:

// app/posts/[slug]/page.tsx
export const revalidate = 3600

export async function generateStaticParams() {
  const posts = await getAllPosts()
  return posts.map((p) => ({ slug: p.slug }))
}

export default async function PostPage({ params }) {
  const { slug } = await params
  const post = await getPost(slug)
  return <article><h1>{post.title}</h1>{post.body}</article>
}

generateStaticParams tells the build which slugs to prerender. A slug not in the list is rendered on first request, then cached. The revalidate export turns both into ISR.

Change one line and the page becomes SSR:

import { cookies } from 'next/headers'

export default async function PostPage({ params }) {
  const theme = (await cookies()).get('theme')?.value
  // ...
}

Reading a cookie makes the whole route dynamic, because the output now depends on who is asking.

What changed in Next.js 16: Cache Components

Next.js 16 ships a newer model called Cache Components, on by default for new create-next-app projects and enabled in older ones with cacheComponents: true in next.config.ts. It replaces "the whole route is static or dynamic" with a per-component choice:

  • Code that only does predictable work (imports, pure computation) is prerendered automatically.
  • A function or component with "use cache" at the top is cached, with a lifetime set by cacheLife('hours') and invalidated by cacheTag('posts'). Its output goes into the static shell.
  • Anything that reads request data or fetches uncached data must sit inside a <Suspense> boundary. The fallback goes into the static shell and the real content streams in at request time.
import { Suspense } from 'react'
import { cookies } from 'next/headers'
import { cacheLife, cacheTag } from 'next/cache'

export default function BlogPage() {
  return (
    <>
      <h1>Our Blog</h1>                 {/* static */}
      <BlogPosts />                     {/* cached, in the shell */}
      <Suspense fallback={<p>Loading…</p>}>
        <UserGreeting />                {/* streams per request */}
      </Suspense>
    </>
  )
}

async function BlogPosts() {
  'use cache'
  cacheLife('hours')
  cacheTag('posts')
  const posts = await fetch('https://api.example.com/posts').then(r => r.json())
  return <ul>{posts.map(p => <li key={p.id}>{p.title}</li>)}</ul>
}

async function UserGreeting() {
  const name = (await cookies()).get('name')?.value ?? 'there'
  return <p>Hi {name}</p>
}

The result is called Partial Prerendering: one HTML response that is part static, part streamed. Reading cookies() in UserGreeting no longer makes the whole page dynamic, which is the big practical difference from the older model. The dev overlay flags any request-data read that sits outside a Suspense boundary and tells you which route is blocked, so a slow page is hard to ship by accident.

ISR still exists under this model. generateStaticParams prerenders the slugs you list; any other URL gets the app shell instantly and is upgraded in the background. The cacheLife profile's revalidate and expire values play the role the old revalidate export did.

These snippets follow the current Next.js docs; I have not run them against a fresh project, so check the exact API names against the version you are on.

Questions interviewers ask

  • What is hydration, and why can it fail? Attaching React's event handlers to server-rendered HTML. It fails when the server and client render different markup, for example when you render Date.now() or window.innerWidth during the first render.
  • When would you choose SSR over SSG? When the output depends on the request: personalised dashboards, auth-gated pages, search results. For anything that is the same for everyone, SSG or ISR wins on cost and speed.
  • How is ISR different from SSR with a CDN cache? ISR is stale-while-revalidate built into the framework: the stale page is served while a new one is built, and you can also invalidate on demand with revalidatePath or revalidateTag after a mutation.
  • Can a Server Component import a Client Component? Yes. The reverse is not allowed as an import, but you can pass a Server Component to a Client Component as children or any other prop.
  • Why can't Server Components use useState? They run once on the server and send their output; there is no instance living in the browser to hold state.
  • Where does a "use cache" result live? By default in memory on the server instance (which does not survive serverless cold starts), in the prerendered output if it was computed at build time, and in the browser for the duration of its stale window. "use cache: remote" moves it to a shared cache handler.

Go deeper

  • Next.js docs: Caching and Incremental Static Regeneration with Cache Components (nextjs.org/docs/app/getting-started/caching)
  • Next.js docs: Server and Client Components
  • React docs: Server Components reference (react.dev)
  • Vercel's "Thinking in PPR" video, ten minutes, linked from the caching page
  • The earlier article on this site, Critical Rendering Path, for what the browser does once the HTML arrives