πΉ SSG (Static Site Generation)
Pre-renders the page at build time into static HTML for fast performance.
πΉ ISR (Incremental Static Regeneration)
Regenerates static pages in the background at a set interval or trigger.
πΉ SSR (Server-Side Rendering)
Renders the page on every request with fresh, dynamic data on the server.
πΉ CSR (Client-Side Rendering)
Loads a blank shell and fetches/render content in the browser after load.
π₯ Rendering Modes Overview
π Quick Setup Guide
β
SSG β Default in App Router
// app/page.tsx
export const revalidate = 3600; // Optional: Regenerate every 1 hour
export default async function Page() {
const res = await fetch('https://api.example.com/posts');
const posts = await res.json();
return <div>{posts.length} posts</div>;
}
π ISR β Add revalidation interval
export const revalidate = 60; // Rebuild page every 60 seconds
π SSR β Always fetch fresh data
export const dynamic = 'force-dynamic'; // or use cache: 'no-store'
const data = await fetch('https://api.example.com/stats', {
cache: 'no-store'
});
π CSR β Client-only rendering
'use client';
import { useEffect, useState } from 'react';
export default function ClientComponent() {
const [data, setData] = useState(null);
useEffect(() => {
fetch('/api/data').then(res => res.json()).then(setData);
}, []);
return <pre>{JSON.stringify(data)}</pre>;
}
π§ When to Use What
π Static content? β SSG
π Refresh every few minutes? β ISR
π€ Authenticated or real-time data? β SSR
π§© Fully interactive UI? β CSR
π Final Tips
β
SSG is the default in App Router (unless you disable caching)
β οΈ Use 'use client' only when absolutely necessary
π Mix & match strategies: server-rendered pages + client components = β‘ powerful UX
π― Are you using the right rendering strategy in your Next.js apps?
If this helped, feel free to save, share, or comment!
Top comments (1)
Awesome cheat sheet! This covers all the rendering strategies perfectly. The visual comparison table is super helpful yaar! π