Topic F12
CSR vs SSR vs SSG
Who builds the HTML and when: the browser, the server, or the build.
Watch: compare when the page's content first appears in all three. Who builds the page decides how soon you see it.
- finished / the result
How they compare
| CSR | SSR | SSG | |
|---|---|---|---|
| First content visible | Slowest | Fast | Fastest |
| Data freshness | Latest | Latest | As old as the last build |
| Server work per request | API only | A full render | None (static files) |
| SEO and link previews | Weak | Good | Good |
| Good for | dashboards behind a login | personalised pages, fast-changing data | docs, blogs, landing pages, this site |
Hydration
With SSR and SSG, the HTML arrives complete but not yet interactive. The JavaScript still has to download and React has to attach event handlers to the elements already there. That process is called hydration. Between content appearing and hydration finishing, the page looks ready but its buttons don't respond yet. A small bundle (previous topic) shortens that gap. React Server Components cut hydration work by sending no JavaScript for components that aren't interactive.
Code, for programmersAll three in Next.js (App Router)
// app/docs/page.tsx: SSG, built once at build time (the default when nothing is dynamic)
export default async function Docs() {
const page = await getDoc("intro");
return <Article page={page} />;
}
// app/blog/page.tsx: ISR, static but rebuilt in the background at most every 60 s
export const revalidate = 60;
// app/account/page.tsx: SSR, rendered on every request (it reads cookies)
export default async function Account() {
const session = (await cookies()).get("session");
return <Profile user={await getUser(session)} />;
}
// components/LiveChart.tsx: CSR, a client component that fetches in the browser
"use client";
export function LiveChart() { const { data } = useQuery({ queryKey: ["live"], queryFn }); /* ... */ }Quiz
Why does a CSR page stay blank longer?
A documentation page that changes once a week. The best choice?
What is hydration?
0 of 3 answered.
Built on
Used in
No follow-up topics yet.