#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
10 min read
•Question 30 of 47hard

Next.js Rendering Strategies Comparison

SSG, SSR, ISR, and dynamic rendering trade-offs.

Rendering Strategies in Next.js

Static Generation (SSG)

code.txtTSX
// Fully static - built at build time
export default async function StaticPage() {
  const data = await fetch('https://api.example.com/data', {
    cache: 'force-cache', // Default - caches indefinitely
  });
  return <div>{data}</div>;
}

// With generateStaticParams
export async function generateStaticParams() {
  const posts = await getPosts();
  return posts.map((post) => ({ slug: post.slug }));
}

Server-Side Rendering (SSR)

code.txtTSX
// Dynamic - rendered on each request
export const dynamic = 'force-dynamic';

export default async function SSRPage() {
  const data = await fetch('https://api.example.com/data', {
    cache: 'no-store', // Always fresh
  });
  return <div>{data}</div>;
}

Incremental Static Regeneration (ISR)

code.txtTSX
// Revalidate after specified seconds
export const revalidate = 60; // Revalidate every 60 seconds

export default async function ISRPage() {
  const data = await fetch('https://api.example.com/data', {
    next: { revalidate: 60 },
  });
  return <div>{data}</div>;
}

// On-demand revalidation
// app/api/revalidate/route.ts
import { revalidatePath, revalidateTag } from 'next/cache';

export async function POST() {
  revalidatePath('/blog');
  // or
  revalidateTag('blog-posts');
  return Response.json({ revalidated: true });
}

Decision Matrix

StrategyBuild TimeRequest TimeUse Case
SSGHeavyFastMarketing, docs
SSRLightSlowerPersonalized, real-time
ISRHeavyFast + FreshBlogs, e-commerce