DEV Community

Cover image for Next.js Rendering Strategies: CSR vs SSR vs SSG vs ISR (Complete Guide) 2025
Rayan Hossain
Rayan Hossain

Posted on

Next.js Rendering Strategies: CSR vs SSR vs SSG vs ISR (Complete Guide) 2025

Understanding how Next.js renders your pages is crucial for building fast, scalable, and SEO-friendly web applications. In this article, we’ll explore Client-Side Rendering (CSR), Server-Side Rendering (SSR), Static Site Generation (SSG), and Incremental Static Regeneration (ISR) — their differences, pros/cons, and when to use them.


🔍 Overview

Next.js offers four main rendering strategies:

  • CSR (Client-Side Rendering): Rendering happens in the browser.
  • SSR (Server-Side Rendering): HTML is rendered on each request.
  • SSG (Static Site Generation): HTML is generated at build time.
  • ISR (Incremental Static Regeneration): Pages are pre-built but can be revalidated after deployment.

Key Concepts

  • Hydration: Turning static HTML into an interactive React app.
  • FCP (First Contentful Paint): When first content appears.
  • TTI (Time To Interactive): When page is fully usable.
  • SEO: How search engines crawl and index your content.

⚡ Client-Side Rendering (CSR)

How it Works

  1. Minimal HTML is served.
  2. Browser downloads JavaScript.
  3. JavaScript fetches data and renders UI.

✅ Pros & ❌ Cons

  • ✅ Great for interactivity
  • ✅ Light on the server
  • ❌ Poor SEO (blank HTML initially)
  • ❌ Slower first load

Example

import { useState, useEffect } from 'react';

export default function CSRExample() {
  const [posts, setPosts] = useState([]);
  useEffect(() => {
    fetch('/api/posts').then(res => res.json()).then(setPosts);
  }, []);

  return (
    <div>
      <h1>Posts (CSR)</h1>
      {posts.map(p => <p key={p.id}>{p.title}</p>)}
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

👉 Best For: Dashboards, private content, real-time apps.


🌐 Server-Side Rendering (SSR)

How it Works

  1. Request comes in.
  2. Server fetches data.
  3. HTML is generated and sent.
  4. Browser hydrates the page.

✅ Pros & ❌ Cons

  • ✅ Fresh data every request
  • ✅ Great SEO
  • ❌ Slower response time
  • ❌ Higher server load

Example

export async function getServerSideProps() {
  const res = await fetch('https://api.example.com/posts');
  const posts = await res.json();
  return { props: { posts } };
}

export default function SSRExample({ posts }) {
  return <ul>{posts.map(p => <li key={p.id}>{p.title}</li>)}</ul>;
}
Enter fullscreen mode Exit fullscreen mode

👉 Best For: E-commerce, news, personalized content.


🚀 Static Site Generation (SSG)

How it Works

  1. At build time, Next.js generates HTML.
  2. Pages are cached on CDN.
  3. Super-fast delivery.

✅ Pros & ❌ Cons

  • ✅ Fastest load times
  • ✅ Great SEO
  • ✅ Very scalable
  • ❌ Stale content until rebuild

Example

import { notFound } from "next/navigation";

async function getPost(id) {
  const res = await fetch(
    `https://jsonplaceholder.typicode.com/posts/${id}`,
  );
  if (!res.ok) {
    return null;
  }
  return res.json();
}

export async function generateStaticParams() {
  const res = await fetch("https://jsonplaceholder.typicode.com/posts");
  const posts = await res.json();

  return posts.map((post) => ({
    id: post.id.toString(),
  }));
}

export default async function PostPage({ params }) {
  const post = await getPost(params.id);

  if (!post) {
    notFound();
  }

  return (
    <main>
      <h1>{post.title}</h1>
      <p>{post.body}</p>
    </main>
  );
}
Enter fullscreen mode Exit fullscreen mode

👉 Best For: Blogs, docs, marketing pages.


🔄 Incremental Static Regeneration (ISR)

How it Works

  1. Pages are generated at build time (like SSG).
  2. Pages are revalidated in the background.
  3. Next visitors get the fresh content.

✅ Pros & ❌ Cons

  • ✅ Speed of SSG + freshness of SSR
  • ✅ No full rebuilds needed
  • ❌ Temporary stale content

Example

export const revalidate = 60

import { notFound } from "next/navigation";

async function getPost(id) {
  const res = await fetch(
    `https://jsonplaceholder.typicode.com/posts/${id}`,
  );
  if (!res.ok) {
    return null;
  }
  return res.json();
}

export async function generateStaticParams() {
  const res = await fetch("https://jsonplaceholder.typicode.com/posts");
  const posts = await res.json();

  return posts.map((post) => ({
    id: post.id.toString(),
  }));
}

export default async function PostPage({ params }) {
  const post = await getPost(params.id);

  if (!post) {
    notFound();
  }

  return (
    <main>
      <h1>{post.title}</h1>
      <p>{post.body}</p>
    </main>
  );
}
Enter fullscreen mode Exit fullscreen mode

👉 Best For: E-commerce catalogs, news sites, frequently updated blogs.


📊 Comparison Chart

Feature CSR SSR SSG ISR
Initial Load Slow Medium Fastest Fast
SEO Poor Excellent Excellent Excellent
Freshness High High Low Medium
Server Load Low High Very Low Low
Best For Apps Dynamic pages Blogs, docs Hybrid needs

💡 When to Use What

  • CSR: Dashboards, authenticated apps, real-time updates.
  • SSR: SEO + fresh content, e-commerce, user-specific pages.
  • SSG: Marketing sites, blogs, documentation.
  • ISR: Large sites, e-commerce catalogs, news portals.

🎯 Exercises for You

  1. Pick a blog and implement SSG with dynamic routes.
  2. Create a dashboard with CSR (fetch on client).
  3. Build a news site homepage with ISR.
  4. Compare performance using Lighthouse.

📌 Final Thoughts

Each rendering strategy in Next.js serves different needs:

  • CSR = Flexibility
  • SSR = Real-time + SEO
  • SSG = Performance
  • ISR = Balance between speed and freshness

By mixing them wisely, you can build fast, SEO-friendly, and scalable apps.


🔗 Additional Resources

Top comments (0)