4/5/2025, 6:37:55 PM
Mohit Kushwah
In the world of modern web development, performance and user experience are everything. With the rise of frameworks like Next.js, developers are equipped with powerful rendering options like Server-Side Rendering (SSR) and Client-Side Rendering (CSR). But how do you know which one to use? In this blog, we’ll break down SSR and CSR in the context of Next.js, highlighting their differences, use-cases, pros, and cons.
Rendering is the process of converting your application code (React components, in the case of Next.js) into HTML that can be shown in the browser. This can be done on the server or client depending on your chosen approach.
Server-Side Rendering means the HTML for a page is generated on the server at the time of the request.
In Next.js:
You use SSR by exporting the getServerSideProps function in your page component:
export async function getServerSideProps(context) {
const res = await fetch('https://api.example.com/data')
const data = await res.json()
return {
props: { data }, // will be passed to the page component as props
}
}
Client-Side Rendering means the page is rendered in the browser using JavaScript. The initial HTML is minimal and data is fetched after the page loads.
CSR is the default behavior in traditional React components or when you use hooks like useEffect() to fetch data:
import { useEffect, useState } from 'react'
export default function Page() {
const [data, setData] = useState(null)
useEffect(() => {
fetch('/api/data')
.then((res) => res.json())
.then((data) => setData(data))
}, [])
return <div>{data ? <p>{data.message}</p> : <p>Loading...</p>}</div>
}
Next.js allows you to combine SSR and CSR within your app. For example, you might use SSR for your homepage and CSR for the dashboard. This flexibility is one of the biggest strengths of Next.js. You can also use Static Site Generation (SSG) and Incremental Static Regeneration (ISR) for even more optimization — but that’s a topic for another blog!