โจ Mastering Rendering Methods in Next.js
Learn how Next.js lets you choose the best rendering approach for your page โ with performance, SEO, and user experience in mind.
โจ Introduction
Next.js is a powerful React framework โ but what truly sets it apart is how flexibly it handles rendering. Whether you want blazing-fast static pages, dynamic server-rendered data, or a mix of both, Next.js has a rendering method for you.
In this post, weโll explore:
- ๐ Client-Side Rendering (CSR)
- ๐ Server-Side Rendering (SSR)
- ๐ฆ Static Site Generation (SSG)
- ๐ Incremental Static Regeneration (ISR)
- โก Hybrid Rendering
- ๐งช Streaming and Server Components
๐ 1. Client-Side Rendering (CSR)
The HTML is sent empty. Your browser does all the work using JavaScript.
โ
Great for: Authenticated dashboards, user-specific pages, apps without SEO needs.
'use client'
export default function Dashboard() {
const [data, setData] = useState(null)
useEffect(() => {
fetch('/api/data')
.then(res => res.json())
.then(setData)
}, [])
return <div>{data ? data.name : 'Loading...'}</div>
}
๐ง Pros: Interactive, lightweight initial build
โ ๏ธ Cons: Poor SEO, slower first render
๐ 2. Server-Side Rendering (SSR)
Every time a user requests the page, the server builds the HTML in real-time.
โ
Great for: Search pages, personalized content, SEO-critical pages
export async function getServerSideProps(context) {
const res = await fetch('https://api.example.com/data')
const data = await res.json()
return { props: { data } }
}
๐ง Pros: Fresh data, SEO-friendly
โ ๏ธ Cons: Slower performance, depends on server response time
๐ฆ 3. Static Site Generation (SSG)
The HTML is built once at build time. Fast and reliable!
โ
Great for: Blogs, marketing pages, documentation, landing pages
export async function getStaticProps() {
const res = await fetch('https://api.example.com/posts')
const posts = await res.json()
return { props: { posts } }
}
๐ง Pros: Super-fast, globally cached
โ ๏ธ Cons: Data can become stale
๐ 4. Incremental Static Regeneration (ISR)
Regenerate static pages after deployment without rebuilding the whole site.
โ
Great for: News articles, product listings, event pages
export async function getStaticProps() {
const res = await fetch('https://api.example.com/events')
const events = await res.json()
return {
props: { events },
revalidate: 60,
}
}
๐ง Pros: Combines speed and freshness
โ ๏ธ Cons: Slight delay before changes are visible
โก 5. Hybrid Rendering
Mix and match rendering methods on a per-page basis.
โ
Great for: Real-world apps with mixed needs
// blog/[slug] โ SSG
// profile โ SSR
// dashboard โ CSR
๐ง Pros: Best of all worlds
โ ๏ธ Cons: Needs careful planning
๐งช 6. Streaming & Server Components (App Router)
With the App Router, Next.js uses React Server Components and supports streaming for faster performance and less JS.
โ
Great for: Modern apps needing performance and minimal JS
// app/posts/page.jsx
export default async function PostsPage() {
const posts = await getPosts()
return <PostsList posts={posts} />
}
๐ง Pros: Lightweight pages, performance gains
โ ๏ธ Cons: Requires App Router + React 18
๐ Comparison Table
| Method | SEO | Speed | Freshness | Best For |
|---|---|---|---|---|
| CSR | โ | โ ๏ธ | โ | Dashboards |
| SSR | โ | โ ๏ธ | โ | Search, Auth pages |
| SSG | โ | โ | โ | Blogs, Docs |
| ISR | โ | โ | โ | News, E-commerce |
| RSC | โ | โ | โ | Modern, large apps |
๐ Final Thoughts
The real power of Next.js is in choosing the right tool for the job. Whether you want pre-rendering at build time or real-time data for every request, Next.js gives you full control.
๐ง "Use SSG when you can, SSR when you must, CSR when it makes sense."
Top comments (0)