What is Server-Side Rendering (SSR)?
Server-Side Rendering (SSR) is a web rendering strategy where HTML is generated on the server for each request and sent to the browser ready to display. The browser shows content immediately; JavaScript then "hydrates" the page to make it interactive. SSR contrasts with Client-Side Rendering (CSR), where the server sends nearly-empty HTML and JS builds the page in the browser.
SSR is the default rendering mode for modern frameworks like Next.js, Nuxt, SvelteKit, and Remix. It's the right choice for content that's dynamic per-request (personalized dashboards, search results, e-commerce with live inventory) and for SEO-critical pages where slow CSR hurts ranking.
How SSR works
- Browser requests
/products/42 - Server fetches data, runs your component tree, generates HTML
- Server returns HTML — browser displays it immediately (fast LCP)
- Browser downloads JavaScript bundle
- JS "hydrates" the HTML, attaching event handlers (page becomes interactive)
The user sees content during step 3 — no white screen.
SSR vs other rendering strategies
| Strategy | HTML generated | Trade-off |
|---|---|---|
| SSR | Per request, on server | Fresh content + SEO; needs server |
| SSG (Static) | Once at build time | Fastest delivery; stale until rebuild |
| CSR | In browser via JS | App-like UX; slow first paint, bad SEO |
| ISR | Build + on-demand re-build | Static perf + dynamic freshness |
| Edge SSR | Per request at CDN edge | Low-latency global; runtime limits |
When SSR is the right choice
- Per-user personalization. Logged-in dashboard with user-specific data.
- Frequently changing content. Live e-commerce inventory, news.
- SEO-critical with dynamic data. Search results, product pages.
- Geo-localized content. Region-specific pricing, language detection.
- A/B testing at the page level. Different HTML per variant.
- Heavy auth/session logic. Server checks identity before sending content.
When NOT to use SSR
- Static marketing pages. Use SSG — no server needed; CDN-cacheable.
- Logged-in dashboards with no SEO need. CSR is fine; cheaper to host.
- Highly interactive apps with simple home page. Mix: SSG for landing, CSR for app.
SSR pros and cons
| Pros | Cons |
|---|---|
| Fast first paint (LCP) | Slower TTFB than SSG |
| SEO-friendly out-of-box | Needs running server |
| Always fresh content | Higher hosting cost at scale |
| Per-user personalization | Cache complexity |
| No client-side data fetching for first render | Server bugs become user-facing |
Hydration: the SSR catch
After SSR sends HTML, the client must "hydrate" — re-run components in the browser to attach event handlers. Hydration is expensive:
- Entire React/Vue tree re-runs
- Bundle must download + parse
- Events delayed until hydration completes (hurts INP)
Modern solutions: Streaming SSR (React 18), Partial Hydration (Astro Islands), Resumability (Qwik), React Server Components (skip JS for non-interactive parts).
SSR with Next.js (App Router)
// app/products/[id]/page.tsx
export default async function ProductPage({ params }: { params: { id: string } }) {
const product = await fetchProduct(params.id); // runs on server
return (
<div>
<h1>{product.name}</h1>
<p>${product.price}</p>
<BuyButton id={product.id} /> {/* Client component */}
</div>
);
}SSR with Express + React (vanilla)
import { renderToString } from 'react-dom/server';
import App from './App';
app.get('/', (req, res) => {
const html = renderToString(<App />);
res.send(`
<!DOCTYPE html>
<html>
<body>
<div id="root">${html}</div>
<script src="/client.js"></script>
</body>
</html>
`);
});SSR best practices
- Cache wisely. Per-user pages can't be edge-cached, but per-locale or per-segment can.
- Use streaming SSR. Stream HTML chunks; user sees content faster.
- Server-only data fetching. Frameworks like Next App Router skip the client-fetch waterfall.
- Cache database queries server-side. Per-request, especially for repeated calls.
- Set cache headers thoughtfully.
Cache-Control: privatefor user-specific. - Watch hydration cost. Use partial hydration / server components for non-interactive content.
- Handle errors at server. Don't leak stack traces to client; render error page.
- Monitor TTFB + LCP. SSR shifts work to server; instrument it.
Common SSR pitfalls
- Window/document references in server-rendered code. No DOM on server; crashes with
ReferenceError: window is not defined. - Server-client mismatch. SSR HTML differs from client render; hydration warning.
- Slow database queries blocking response. SSR holds the connection until HTML ready.
- Forgetting to cache. Every request hits database; doesn't scale.
- Bundle bloat. SSR sends server-only deps to client by accident.
- Memory leaks. SSR is long-running; small leaks compound.
- Auth in middleware. Slow auth check = slow TTFB on every request.
FAQ: Server-Side Rendering
SSR or SSG: which is better?
Depends on content freshness. Static content rarely changing → SSG. Dynamic per-request content → SSR. Middle ground → ISR.
Does SSR fix SEO automatically?
SSR ensures crawlers get HTML, but you still need title, meta, structured data, sitemap, fast Core Web Vitals.
Is SSR slower than CSR?
For TTFB: SSR is slower (server work). For first contentful paint: SSR is much faster (HTML arrives ready). User perception: SSR feels faster.
What about TTFB with SSR?
Higher than SSG/static. Mitigate with edge SSR, caching layers (Redis), CDN cache for non-personalized routes.
Can I mix SSR and CSR?
Yes — most apps do. Public pages SSR for SEO; logged-in dashboard can be CSR. Frameworks (Next.js, SvelteKit) support per-route choices.
What's React Server Components?
A React feature where some components run only on the server and never ship JS to client. Different from SSR — RSC is a finer-grained control.
Is SSR expensive to host?
More than SSG (needs running compute). Modern serverless (Vercel, Lambda@Edge, Cloudflare Workers) make it cheap at low traffic; can scale up cost at high traffic.
Load test SSR apps with LoadFocus
SSR shifts work to your server — load testing is essential. LoadFocus runs JMeter and k6 from 25+ regions to verify SSR performance under traffic. Sign up free at loadfocus.com/signup.
Related LoadFocus Tools
Put this concept into practice with LoadFocus — the same platform that powers everything you just read about.