Catalog My learning Blog
Frontend Developer Course: 100 Concepts in 100 Days · Phase 8 · Lesson 71 · 6 min read

CSR vs SSR vs SSG vs ISR Explained

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: One Product, Four Strategies by Route
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Compare client-side rendering, server-side rendering, static site generation and incremental static regeneration by when and where HTML is produced, their effects on loading performance, SEO, freshness, personalization and infrastructure, and choose a strategy per route rather than per application.

Concept Explanation

Every page's HTML has to be produced somewhere, at some time. The choices differ in where, the browser or a server, and when, at build time or at request time, and those two questions determine much of a page's performance profile, its cost and its suitability for search engines and link previews.

Client-side rendering, CSR, sends a nearly empty HTML document with script tags. The browser downloads and runs the JavaScript, which fetches data and builds the page. It is simple to host, since everything is static files on a CDN, and ideal for highly interactive applications behind a login, such as dashboards and editors. The cost is that nothing meaningful appears until JavaScript has downloaded, executed and fetched data, so first contentful paint and largest contentful paint suffer, especially on slow devices, and crawlers and link preview bots that do not run JavaScript see an empty page.

Server-side rendering, SSR, runs the same components on a server for each request, producing complete HTML with the data already in it. The user sees content as soon as the HTML arrives, and crawlers see everything. The browser then downloads the JavaScript and hydrates the page to make it interactive (Day 72). SSR handles personalized and frequently changing content, such as a logged-in home page or search results, but needs servers that scale with traffic, adds server rendering time to time to first byte and makes caching harder because responses may differ per user.

Static site generation, SSG, renders pages to HTML at build time. The output is plain files served from a CDN close to users, giving the fastest possible delivery and very low cost and attack surface. It suits content that is the same for everyone and changes rarely: documentation, marketing pages, blogs, this course's lesson pages. The limits are freshness, since changes require a rebuild, and scale, since millions of pages take a long time to build.

Incremental static regeneration, ISR, and similar revalidation features combine the two. Pages are generated statically, served from cache, and regenerated in the background after a time interval or when the application signals that data changed, so product pages can be static yet update within minutes of a price change, and pages not built at deploy time can be generated on first request. Under the hood this is stale-while-revalidate applied to HTML (Day 63).

The modern answer is to choose per route. A typical product might statically generate its marketing pages, use ISR for product pages, server-render search results and render the logged-in dashboard on the client. Meta-frameworks such as Next.js, Nuxt, SvelteKit, Astro and Remix let each route pick its strategy, and partial approaches, such as static shells with dynamic holes, blur the lines further (Days 73 and 75).

StrategyHTML producedStrengthsWeaknesses
CSRIn the browser, after JavaScript runsSimple static hosting, rich interactivitySlow first paint, poor for crawlers
SSROn the server, per requestFast content, personalized, SEO friendlyServer cost, slower TTFB, harder caching
SSGAt build timeFastest delivery from CDN, cheap, secureStale until rebuild, long builds at scale
ISR or revalidationAt build, then regenerated in backgroundStatic speed with freshnessBrief staleness, platform support needed
Per route mixEach route choosesBest fit for each pageMore concepts to manage

Worked Example: One Product, Four Strategies by Route

A Next.js App Router project picks a strategy for each route. The comments note why each choice fits.

Shell
// app/(marketing)/pricing/page.tsx: static at build time, same for everyone
export const dynamic = 'force-static';
export default function Pricing() {
  return <PricingTable plans={PLANS} />;               // no request-time data
}

// app/products/[slug]/page.tsx: static, regenerated at most every 10 minutes or on demand
export const revalidate = 600;
export async function generateStaticParams() {
  return (await getTopProducts(500)).map((p) => ({ slug: p.slug }));   // others render on first request
}
export default async function ProductPage({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const product = await getProduct(slug);
  if (!product) notFound();
  return <ProductDetail product={product} />;
}

// app/api/revalidate/route.ts: the CMS calls this when a product changes
import { revalidatePath } from 'next/cache';
export async function POST(req: Request) {
  if (req.headers.get('x-revalidate-secret') !== process.env.REVALIDATE_SECRET) return new Response('Forbidden', { status: 403 });
  const { slug } = await req.json();
  revalidatePath(`/products/${slug}`);
  return Response.json({ revalidated: true });
}

// app/search/page.tsx: server-rendered per request, results depend on the query
export const dynamic = 'force-dynamic';
export default async function Search({ searchParams }: { searchParams: Promise<{ q?: string }> }) {
  const { q = '' } = await searchParams;
  return <Results items={await search(q)} query={q} />;
}

// app/dashboard/page.tsx: behind login, highly interactive, rendered on the client
'use client';
export default function Dashboard() {
  const stats = useQuery({ queryKey: ['stats'], queryFn: api.stats });
  return <DashboardView stats={stats} />;
}

Opening view-source on each route shows the difference: pricing and product pages contain full content, the search page contains results for the query in the URL, and the dashboard route's useful content appears only after its client query resolves.

Client-side rendering builds HTML in the browser after JavaScript runs, server-side rendering builds it per request, static generation builds it at deploy time and incremental regeneration rebuilds static pages in the background. Each route can choose.
Client-side rendering builds HTML in the browser after JavaScript runs, server-side rendering builds it per request, static generation builds it at deploy time and incremental regeneration rebuilds static pages in the background. Each route can choose.

Real-World Examples

  • This course's own lesson pages are statically generated HTML built from a database at deploy time, which is why they load quickly from a CDN, work without JavaScript and are fully visible to search engines and AI crawlers.
  • Next.js introduced incremental static regeneration in version 9.5 in 2020, and other frameworks adopted similar ideas, such as Nuxt's route rules with stale-while-revalidate and SvelteKit's prerendering with configurable caching on edge platforms.
Key TakeawaysCSR, SSR, SSG and ISR differ in where and when each page is rendered, and each one suits a different kind of page. CSR renders in the browser and suits interactive apps behind a login, SSR renders per request for personalized and fast-changing content, SSG renders at build time for the fastest and cheapest delivery, and ISR keeps static pages fresh by regenerating them in the background. Choose per route by asking who sees the page, how often its data changes and whether search engines need it.

Review Questions & Answers

The initial HTML is nearly empty, so meaningful content only appears after the JavaScript bundle downloads, parses and executes, and then fetches data. Each of those steps happens in sequence on the user's device and network before anything useful is painted.

When pages are the same for every visitor and change rarely, such as documentation, marketing pages and blog posts. Prebuilt HTML can be served from a CDN with the best speed, lowest cost and smallest attack surface.

Freshness without full rebuilds. Static pages are served from cache and regenerated in the background after a set interval or on demand when data changes, and pages not built at deploy time can be generated and cached on first request.

Different pages have different needs: a pricing page is identical for everyone, a product page changes occasionally, search results depend on each query and a dashboard is private and interactive. A single strategy would be wrong for some of them, while per-route choices fit each one.