DEV Community

Cover image for Mastering Rendering Methods in Next.js ๐Ÿง โšก
Muhammad Hamid Raza
Muhammad Hamid Raza

Posted on • Edited on • Originally published at hamidrazadev.vercel.app

Mastering Rendering Methods in Next.js ๐Ÿง โšก

โœจ 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>
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  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 } }
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  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 } }
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  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,
  }
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  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
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  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} />
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  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)