JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsnextjs
Next
nextjs
senior
rendering

Explain the different rendering strategies in Next.js (SSR, SSG, ISR) and when to use each approach.

nextjs
ssr
ssg
isr
rendering
performance
caching
server-components
Quick Answer

Next.js offers multiple rendering strategies: Static Site Generation (SSG) for build-time rendering, Server-Side Rendering (SSR) for per-request rendering, Incremental Static Regeneration (ISR) for static pages with background revalidation, and hybrid approaches that mix strategies per route based on content requirements.

Detailed Explanation

Rendering Strategies Overview

Next.js provides flexible rendering strategies that can be mixed and matched across your application:

Static Site Generation (SSG)

  • HTML generated at build time
  • Cached and served from CDN
  • Fastest performance, best for SEO
  • Use for: blogs, documentation, marketing pages, product listings

Server-Side Rendering (SSR)

  • HTML generated on each request
  • Fresh data on every page load
  • Higher server load, slower TTFB
  • Use for: personalized content, real-time data, authenticated pages

Incremental Static Regeneration (ISR)

  • Static pages that revalidate in background
  • Combines SSG speed with data freshness
  • Stale-while-revalidate pattern
  • Use for: e-commerce products, news articles, frequently updated content

Client-Side Rendering (CSR)

  • JavaScript renders content in browser
  • Initial page shell is fast, content loads after
  • Use for: dashboards, private content, highly interactive UIs

App Router Specifics

With React Server Components, the model shifts:

  1. Static by Default: Server Components render once at build time unless they use dynamic functions
  2. Dynamic Functions: Using cookies(), headers(), searchParams, or unstable_noStore() opts into dynamic rendering
  3. Time-Based Revalidation: fetch with next: { revalidate: 60 } enables ISR-like behavior
  4. On-Demand Revalidation: revalidatePath() and revalidateTag() for manual cache invalidation

Hybrid Approaches

Real-world apps often combine strategies:

  • Per-Route Strategy: Marketing pages (SSG), dashboard (SSR), blog (ISR)
  • Partial Rendering: Static shell with dynamic islands using Suspense
  • Streaming: Progressive HTML streaming for faster perceived performance

Code Examples

Pages Router - Different Rendering Strategies
// pages/static.tsx - SSG (default)
export default function StaticPage({ data }) {
  return <div>{data.title}</div>;
}

export async function getStaticProps() {
  const data = await fetchData();
  return { props: { data } };
}

// pages/ssr.tsx - SSR
export async function getServerSideProps(context) {
  const { req, res, query } = context;
  const data = await fetchUserData(req.cookies.userId);
  return { props: { data } };
}

// pages/isr.tsx - ISR with 60-second revalidation
export async function getStaticProps() {
  const data = await fetchProducts();
  return {
    props: { data },
    revalidate: 60, // Regenerate every 60 seconds
  };
}

Resources

Rendering - Next.js Documentation

docs

Data Fetching, Caching, and Revalidating

docs

Related Questions

How does caching and revalidation work in Next.js?

senior
caching

What's the difference between Server Components and Client Components in Next.js?

mid
components
Next
What are Server Actions in Next.js and how do they handle form submissions and mutations?