Server-Side Rendering (SSR): Definition, Pros, When to Use

SSR generates HTML on the server per request — fast first paint, SEO-friendly, dynamic. Used by Next.js, Nuxt, Remix, SvelteKit, Rails+Turbo.

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

  1. Browser requests /products/42
  2. Server fetches data, runs your component tree, generates HTML
  3. Server returns HTML — browser displays it immediately (fast LCP)
  4. Browser downloads JavaScript bundle
  5. 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

StrategyHTML generatedTrade-off
SSRPer request, on serverFresh content + SEO; needs server
SSG (Static)Once at build timeFastest delivery; stale until rebuild
CSRIn browser via JSApp-like UX; slow first paint, bad SEO
ISRBuild + on-demand re-buildStatic perf + dynamic freshness
Edge SSRPer request at CDN edgeLow-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

ProsCons
Fast first paint (LCP)Slower TTFB than SSG
SEO-friendly out-of-boxNeeds running server
Always fresh contentHigher hosting cost at scale
Per-user personalizationCache complexity
No client-side data fetching for first renderServer 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: private for 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.

How fast is your website?

Elevate its speed and SEO seamlessly with our Free Speed Test.

Free Website Speed Test

Analyze your website's load speed and improve its performance with our free page speed checker.

×