Clean • Professional
When building modern React applications, performance and SEO are critical. However, traditional React apps (created with CRA or Vite) are client-side rendered, meaning the browser loads a blank page first and then runs JavaScript to render the UI.
This can hurt SEO, page load speed, and user experience — especially on slower networks.
That’s where Next.js comes in. It adds powerful features like Server-Side Rendering (SSR) and Static Site Generation (SSG) to React — helping you build fast, SEO-friendly, and production-ready apps.
Server-Side Rendering (SSR) means that the HTML for a page is generated on the server for every request — instead of being generated on the client (browser).
When a user visits your website:
Let’s create a simple Next.js page that fetches data using SSR:
// pages/users.js
import React from "react";
function Users({ users }) {
return (
<div>
<h1>Server-Side Rendered Users</h1>
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
</div>
);
}
// SSR function — runs on the server for every request
export async function getServerSideProps() {
const res = await fetch("<https://jsonplaceholder.typicode.com/users>");
const users = await res.json();
return { props: { users } };
}
export default Users;
getServerSideProps() runs on the server before the page is rendered.Static Site Generation (SSG) means that HTML pages are pre-rendered at build time — not on every request.
When you build your Next.js app (npm run build):
// pages/blog.js
import React from "react";
function Blog({ posts }) {
return (
<div>
<h1>Static Site Generated Blog</h1>
<ul>
{posts.map((post) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
</div>
);
}
// SSG function — runs only once during build time
export async function getStaticProps() {
const res = await fetch("<https://jsonplaceholder.typicode.com/posts?_limit=5>");
const posts = await res.json();
return { props: { posts } };
}
export default Blog;
getStaticProps() runs at build time, not per request.| Feature | SSR (Server-Side Rendering) | SSG (Static Site Generation) |
|---|---|---|
| When HTML is Generated | On every request | At build time |
| Performance | Slower (runs for each request) | Super fast (pre-built) |
| Data Freshness | Always up-to-date | May become stale |
| SEO Friendly | Yes | Yes |
| Use Case | Dynamic content (user dashboards, live data) | Static content (blogs, product pages) |
Next.js allows you to mix SSR and SSG in the same app.
For example:
This flexibility gives you the best of both worlds — performance and freshness.
Next.js also offers Incremental Static Regeneration (ISR) — a hybrid approach between SSR and SSG.
It allows you to:
Example:
export async function getStaticProps() {
const res = await fetch("<https://api.example.com/data>");
const data = await res.json();
return {
props: { data },
revalidate: 60, // Rebuild the page every 60 seconds
};
}
1. Server-Side Rendering (SSR)
SSR (Server-Side Rendering) means pages are rendered on the server for each request and sent as ready-to-view HTML to the browser.
Benefits:
_20251104_090521.png&w=3840&q=75)
2. Static Site Generation (SSG)
SSG (Static Site Generation) means pages are pre-rendered at build time and served as static files.
Benefits:
_20251104_090541.png&w=3840&q=75)