Files
2nd/10_Wiki/Topics/Architecture/Web-Rendering-Strategies-CSR-vs-SSR.md
T
2026-05-10 22:08:15 +09:00

185 lines
5.9 KiB
Markdown

---
id: wiki-2026-0508-web-rendering-strategies-csr-vs-
title: Web Rendering Strategies — CSR vs SSR
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [CSR vs SSR, SSG, ISR, Rendering Strategies, Hybrid Rendering]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [rendering, ssr, csr, ssg, isr, frontend, performance]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: typescript
framework: nextjs
---
# Web Rendering Strategies — CSR vs SSR
## 매 한 줄
> **"매 어디서 render 매 (server/build/client/edge), 매 언제 (request/build/runtime), 매 무엇 (static/dynamic) — 매 이 3 축 의 매 trade-off"**. 매 2026 매 hybrid (RSC + Streaming SSR + ISR + Edge) 매 default — Next.js / Nuxt / Remix / SvelteKit / Astro 매 모두 mix.
## 매 핵심
### 매 5 가지 strategy
- **CSR (Client-Side Rendering)**: empty HTML + JS bundle → browser 매 render. SPA classic.
- **SSR (Server-Side Rendering)**: per-request HTML on server.
- **SSG (Static Site Generation)**: build-time HTML.
- **ISR (Incremental Static Regeneration)**: SSG + on-demand or time-based revalidate.
- **RSC (React Server Components, 2023~)**: server-only component, zero JS ship for that part.
### 매 핵심 metric
- **TTFB**: server response time.
- **FCP / LCP**: 매 visible content speed.
- **TTI**: 매 interactive — hydration cost.
- **INP**: 매 interaction latency (FID 의 후속, Core Web Vitals 2024+).
- **JS bundle**: 매 작을 수록 hydration fast.
### 매 응용
1. Marketing site → SSG / ISR (Astro, Next).
2. E-commerce → ISR + dynamic SSR for cart.
3. Dashboard / admin → CSR or SSR with auth.
4. Blog → SSG + ISR.
5. Real-time chat → CSR + SSE/WebSocket.
6. News site → ISR (revalidate every 60s).
## 💻 패턴
### Next.js App Router (RSC + streaming)
```tsx
// app/products/[id]/page.tsx — RSC, fetched on server, no JS shipped
export default async function ProductPage({ params }: { params: { id: string } }) {
const product = await db.product.findUnique({ where: { id: params.id } });
return (
<article>
<h1>{product.name}</h1>
<Suspense fallback={<Skeleton />}>
<Reviews productId={params.id} />
</Suspense>
</article>
);
}
```
### ISR with revalidate
```tsx
// Next.js — 매 60s 마다 background regenerate
export const revalidate = 60;
export default async function Posts() {
const posts = await fetch("https://api.example.com/posts").then((r) => r.json());
return <ul>{posts.map((p) => <li key={p.id}>{p.title}</li>)}</ul>;
}
```
### SSG with `generateStaticParams`
```tsx
export async function generateStaticParams() {
const slugs = await getAllSlugs();
return slugs.map((slug) => ({ slug }));
}
```
### CSR via dynamic + ssr:false
```tsx
"use client";
import dynamic from "next/dynamic";
const Chart = dynamic(() => import("./HeavyChart"), { ssr: false });
export default function Page() { return <Chart />; }
```
### Streaming SSR (Suspense)
```tsx
// app/dashboard/page.tsx
export default function Dashboard() {
return (
<>
<Header />
<Suspense fallback={<Skel />}><SlowWidget /></Suspense>
<Suspense fallback={<Skel />}><AnotherSlow /></Suspense>
</>
);
}
// 매 shell 먼저 flush, 매 widget ready 시 stream
```
### Edge runtime (Vercel / Cloudflare Workers)
```ts
// Next.js — Edge 매 cold start 매 0 에 가까움
export const runtime = "edge";
export async function GET(req: Request) {
const country = req.headers.get("x-vercel-ip-country") ?? "US";
return new Response(`Hello from ${country}`);
}
```
### Astro islands
```astro
---
// 매 default static, 매 island 만 hydrate
import Counter from "../components/Counter.tsx";
const posts = await fetch("...").then((r) => r.json());
---
<html>
<body>
{posts.map((p) => <article><h2>{p.title}</h2></article>)}
<Counter client:visible /> <!-- viewport entry 시 hydrate -->
</body>
</html>
```
### On-demand revalidation
```ts
// Next.js — webhook 받으면 매 즉시 invalidate
import { revalidateTag, revalidatePath } from "next/cache";
export async function POST(req: Request) {
const { tag } = await req.json();
revalidateTag(tag);
return Response.json({ ok: true });
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Static marketing | SSG / Astro |
| Blog with comments | SSG + CSR comments |
| News feed (changes hourly) | ISR (revalidate=3600) |
| Product page + cart | RSC + Client island for cart |
| Real-time dashboard | CSR + WebSocket |
| Geo-personalized | Edge SSR |
| Authenticated app | SSR with auth + RSC |
**기본값**: Next.js App Router (RSC default) + Suspense streaming + ISR for content. 매 client component 매 조심히.
## 🔗 Graph
- 부모: [[Frontend Architecture]] · [[Web Performance]]
- 변형: [[CSR]] · [[SSR]] · [[SSG]] · [[ISR]] · [[RSC]]
- 응용: [[Next.js App Router]] · [[Nuxt 3]] · [[Astro]] · [[SvelteKit]] · [[Remix]]
- Adjacent: [[Streaming SSR]] · [[Edge Runtime]] · [[Hydration]] · [[Core Web Vitals]] · [[Islands Architecture]]
## 🤖 LLM 활용
**언제**: Rendering strategy 결정, Next.js / Nuxt / Astro setup, Core Web Vitals tuning.
**언제 X**: Pure native app, internal CLI, embedded device UI.
## ❌ 안티패턴
- **CSR for SEO-critical content**: 매 crawler 매 problem.
- **SSR everywhere without caching**: 매 server CPU 폭발 — ISR / cache 도입.
- **Hydration mismatch**: server HTML ≠ client render — 매 console error + flicker.
- **Massive client bundle**: 매 hydration TTI 늦어짐 — RSC / island 활용.
- **No streaming**: 매 slow API 매 entire page block — Suspense.
- **Misuse of `"use client"`**: 매 RSC tree 의 매 leaf 만 client.
## 🧪 검증 / 중복
- Verified (Next.js 15 docs, Vercel team blog, web.dev rendering guide 2025).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — RSC, streaming, ISR, edge runtime patterns |