The Restaurant Analogy
Two types of restaurants:
Prepared meal (SSR):
- Kitchen prepares complete dish
- Waiter brings ready-to-eat meal
- You enjoy immediately
DIY kit (CSR):
- Kitchen sends ingredients
- You assemble and cook at your table
- Takes time before you can eat
SSR sends complete pages. CSR sends code to build pages.
What Is Rendering?
Rendering = Turning code/data into visible HTML
Someone has to do it:
Server-side: Server creates HTML
Client-side: Browser creates HTML
Both result in the page you see.
Server-Side Rendering (SSR)
How It Works
1. Browser requests page
2. Server runs application code
3. Server fetches data
4. Server generates complete HTML
5. Server sends full HTML to browser
6. Browser displays page immediately
7. JavaScript loads and makes page interactive
Example Flow
Request: GET /products
Server:
- Query database
- Build HTML with product list
- Send complete HTML
Browser:
- Receives full page
- Shows content immediately
- Loads JS for interactivity
Client-Side Rendering (CSR)
How It Works
1. Browser requests page
2. Server sends minimal HTML + JavaScript bundle
3. Browser downloads JavaScript
4. JavaScript runs and fetches data
5. JavaScript builds the page in browser
6. Page becomes visible
Example Flow
Request: GET /products
Server:
- Sends: <div id="root"></div> + app.js
Browser:
- Downloads app.js (large bundle)
- Runs JS
- JS fetches /api/products
- JS builds product list
- Page finally visible
Comparison
| Aspect | SSR | CSR |
|---|---|---|
| First load | Fast (HTML ready) | Slow (JS must load) |
| Subsequent nav | Slower (new HTML) | Fast (just data) |
| SEO | Excellent | Challenging |
| Server load | Higher | Lower |
| Time to content | Quick | Delayed |
| Interactivity | After hydration | After JS runs |
When to Use SSR
Good For
âś“ SEO-critical pages (blogs, marketing)
âś“ Content websites
âś“ E-commerce product pages
âś“ Slow devices or connections
âś“ Social media previews
Example Sites
News sites
E-commerce
Blogs
Landing pages
When to Use CSR
Good For
âś“ Dashboard applications
âś“ Admin panels
âś“ Apps behind login (SEO not needed)
âś“ Highly interactive applications
âś“ Real-time features
Example Sites
Gmail
Figma
Notion
Analytics dashboards
Hydration
SSR sends HTML, but it's not interactive yet.
JavaScript must "hydrate" the page.
Hydration:
1. Server sends HTML (visible)
2. JavaScript loads
3. JS attaches event listeners
4. Page becomes interactive
Time To Interactive (TTI) matters!
Modern Approaches
Static Site Generation (SSG)
Pre-render at build time (not request time).
Fastest possible load.
Good for content that doesn't change often.
Gatsby, Next.js static export.
Incremental Static Regeneration (ISR)
Static pages + background regeneration.
Best of static and dynamic.
Next.js feature.
Streaming SSR
Send HTML in chunks.
User sees content as it arrives.
React 18, Next.js 13+.
Islands Architecture
Mostly static HTML.
Interactive "islands" of JavaScript.
Minimal JS, fast pages.
Astro, Fresh.
Framework Support
| Framework | SSR | CSR | SSG |
|---|---|---|---|
| Next.js | âś“ | âś“ | âś“ |
| Nuxt.js | âś“ | âś“ | âś“ |
| SvelteKit | âś“ | âś“ | âś“ |
| Create React App | âś— | âś“ | âś— |
| Gatsby | âś— | âś“ | âś“ |
| Astro | âś“ | Opt-in | âś“ |
Performance Metrics
First Contentful Paint (FCP)
When user sees first content.
SSR: Fast (HTML has content)
CSR: Slow (wait for JS)
Time to Interactive (TTI)
When page is fully interactive.
SSR: After hydration
CSR: After JS renders
Largest Contentful Paint (LCP)
When main content is visible.
SSR advantage for content-heavy pages.
Common Mistakes
1. SSR for Everything
Dashboard behind login?
SSR adds server load for no SEO benefit.
CSR might be better.
2. CSR for Public Content
Blog posts with CSR?
Search engines may not index properly.
Use SSR or SSG.
3. Ignoring Hydration Cost
SSR page is fast!
But it's not interactive yet.
Measure TTI, not just FCP.
FAQ
Q: Can I mix SSR and CSR?
Yes! Many frameworks support per-page or per-component choice.
Q: Is SSG the same as SSR?
SSG renders at build time (once). SSR renders at request time (every time).
Q: Does SSR solve all SEO issues?
For content, yes. But you also need good meta tags, structure, and content.
Q: Which is faster?
SSR for first load (especially on slow devices). CSR for navigation after first load.
Summary
SSR renders on the server for fast first paint and SEO. CSR renders in the browser for interactivity.
Key Takeaways:
- SSR: Server sends complete HTML
- CSR: Browser builds page from JavaScript
- SSR: Better SEO, faster first paint
- CSR: Better for interactive apps
- SSG: Pre-built at build time (fastest)
- Modern: Mix approaches as needed
Choose based on your needs, or use both!
Related Concepts
Leave a Comment
Comments (0)
Be the first to comment on this concept.
Comments are approved automatically.