β¨ 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)