[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,89 +1,179 @@
|
||||
---
|
||||
id: wiki-2026-0508-incremental-static-regeneration-
|
||||
title: Incremental Static Regeneration ISR
|
||||
title: Incremental Static Regeneration (ISR)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [FE-REND-ISR-001]
|
||||
aliases: [ISR, Stale-While-Revalidate Static, On-Demand Revalidation]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [nextjs, isr, rendering, web-Architecture, ssg, performance, Scalability, seo]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [architecture, nextjs, ssg, caching, web]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-26
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: typescript
|
||||
framework: nextjs
|
||||
---
|
||||
|
||||
# Incremental Static Regeneration: ISR (점진적 정적 재생성)
|
||||
# Incremental Static Regeneration (ISR)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "전체 사이트를 다시 빌드하지 않고도 정적 페이지를 백그라운드에서 실시간으로 업데이트하여, 정적 사이트의 성능(SSG)과 동적 데이터의 최신성(SSR)을 완벽하게 결합하라" — 대규모 콘텐츠 사이트의 확장성과 속도를 해결하는 차세대 렌더링 전략.
|
||||
## 매 한 줄
|
||||
> **"매 static page 의 build-time 의 prerender + runtime 의 stale-while-revalidate 의 통한 fresh 의 hybrid"**. 매 Next.js 9.5 (2020) 의 introduction, 매 Vercel 의 patent (US 11,055,090), 매 modern 의 Next.js 15 App Router 의 `revalidate` + `revalidateTag` + `revalidatePath` 의 first-class.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **추출된 패턴:** "Stale-While-Revalidate at Scale" — 사용자에게는 일단 캐시된 정적 페이지를 즉시 서빙하고, 설정된 주기마다 백그라운드에서 데이터를 갱신하여 다음 사용자에게 최신 페이지를 제공하는 패턴.
|
||||
- **ISR의 핵심 메커니즘:**
|
||||
- **Revalidate Interval:** 초 단위로 갱신 주기를 설정 (예: 60초).
|
||||
- **Background Regeneration:** 주기가 지난 후 첫 요청이 들어오면 기존 페이지를 즉시 보여주되, 서버는 백그라운드에서 새 페이지를 생성.
|
||||
- **Atomic Replacement:** 생성이 완료되면 기존 캐시를 새 페이지로 교체.
|
||||
- **의의:** 수백만 개의 페이지를 가진 이커머스나 뉴스 사이트에서도 빌드 시간을 획기적으로 줄이면서도 최신 정보를 유지할 수 있게 함.
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 과거에는 실시간 정보를 위해 무조건 SSR을 사용했으나, 이는 서버 부하를 가중시켰음. ISR 정책은 '수용 가능한 수준의 최신성'을 타협 정책으로 채택하여 서버 비용과 사용자 경험을 최적화함.
|
||||
- **정책 변화:** Antigravity 프로젝트는 상품 상세 페이지 및 카테고리 목록에 대해 기본적으로 ISR 정책을 적용하며, 재고 정보와 같은 극도로 민감한 데이터에 한해서만 부분적인 클라이언트 사이드 데이터 페칭 정책을 결합함.
|
||||
### 매 ISR 동작
|
||||
1. Build 시 page 의 prerender → static HTML + JSON.
|
||||
2. Request 의 cached HTML 의 즉시 serve.
|
||||
3. `revalidate: N` 초 후 첫 request 의 background regenerate trigger.
|
||||
4. 매 그 request 는 stale 의 받음, 매 다음 request 는 fresh.
|
||||
5. On-demand: webhook → `revalidateTag('post-123')` 의 cache 의 invalidate.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- Static-Site-Generation-SSG, Server-Side-Rendering-SSR, [[Web-Rendering-Strategies-CSR-vs-SSR|Web-Rendering-Strategies-CSR-vs-SSR]], [[Nextjs-App-Router-Architecture|Nextjs-App-Router-Architecture]]
|
||||
- **Raw Source:** 00_Raw/Incremental Static Regeneration (ISR).md
|
||||
### 매 ISR vs SSR vs SSG
|
||||
- **SSG**: build-time only, content change → rebuild.
|
||||
- **SSR**: every request, fresh but slow + costly.
|
||||
- **ISR**: prerendered + revalidate window, near-CDN speed + freshness.
|
||||
- **PPR (Partial Prerendering, Next.js 15)**: static shell + dynamic holes — ISR 의 evolution.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. Marketing/blog (수십만 page).
|
||||
2. E-commerce product page (price/stock 의 stale OK seconds).
|
||||
3. Docs site (authored content, low write rate).
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### App Router — Time-Based Revalidate
|
||||
```typescript
|
||||
// app/blog/[slug]/page.tsx
|
||||
export const revalidate = 60; // seconds
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
export default async function Post({ params }: { params: { slug: string } }) {
|
||||
const post = await fetch(`https://cms.example.com/posts/${params.slug}`, {
|
||||
next: { revalidate: 60, tags: [`post:${params.slug}`] },
|
||||
}).then(r => r.json());
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
return <article>{post.title}</article>;
|
||||
}
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
export async function generateStaticParams() {
|
||||
const posts = await fetch('https://cms.example.com/posts').then(r => r.json());
|
||||
return posts.map((p: any) => ({ slug: p.slug }));
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### On-Demand — `revalidateTag`
|
||||
```typescript
|
||||
// app/api/revalidate/route.ts
|
||||
import { revalidateTag } from 'next/cache';
|
||||
import { NextRequest } from 'next/server';
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
export async function POST(req: NextRequest) {
|
||||
const secret = req.headers.get('x-webhook-secret');
|
||||
if (secret !== process.env.WEBHOOK_SECRET) {
|
||||
return new Response('forbidden', { status: 403 });
|
||||
}
|
||||
const { slug } = await req.json();
|
||||
revalidateTag(`post:${slug}`);
|
||||
return Response.json({ revalidated: true, slug });
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### `revalidatePath` (entire route)
|
||||
```typescript
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
export async function publishPost(slug: string) {
|
||||
await db.posts.update({ where: { slug }, data: { published: true } });
|
||||
revalidatePath(`/blog/${slug}`);
|
||||
revalidatePath('/blog');
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Pages Router (legacy `getStaticProps`)
|
||||
```typescript
|
||||
// pages/products/[id].tsx
|
||||
export async function getStaticProps({ params }) {
|
||||
const product = await fetch(`/api/products/${params.id}`).then(r => r.json());
|
||||
return { props: { product }, revalidate: 30 };
|
||||
}
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
export async function getStaticPaths() {
|
||||
const top100 = await fetch('/api/products?top=100').then(r => r.json());
|
||||
return {
|
||||
paths: top100.map((p: any) => ({ params: { id: p.id } })),
|
||||
fallback: 'blocking', // first request 의 SSR-then-cache
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### CMS Webhook → ISR
|
||||
```typescript
|
||||
// Sanity / Contentful / Strapi webhook
|
||||
{
|
||||
"url": "https://app.example.com/api/revalidate",
|
||||
"headers": { "x-webhook-secret": "..." },
|
||||
"events": ["entry.publish", "entry.update"]
|
||||
}
|
||||
```
|
||||
|
||||
### Partial Prerendering (Next.js 15)
|
||||
```typescript
|
||||
// next.config.ts
|
||||
export default { experimental: { ppr: 'incremental' } };
|
||||
|
||||
// app/page.tsx
|
||||
export const experimental_ppr = true;
|
||||
import { Suspense } from 'react';
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<>
|
||||
<StaticHero /> {/* prerendered */}
|
||||
<Suspense fallback={<Skel/>}>
|
||||
<DynamicCart /> {/* streamed at request time */}
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Content-heavy, low write | ISR + on-demand revalidate |
|
||||
| Per-user dashboard | SSR / Server Components (no ISR) |
|
||||
| Pure static (마케팅 사이트) | SSG, no revalidate |
|
||||
| Real-time (stock ticker) | Streaming / WebSocket |
|
||||
| Mixed page (static + dynamic) | PPR (Next.js 15+) |
|
||||
|
||||
**기본값**: 매 content site — App Router + tag-based on-demand revalidation, 매 fallback 의 time-based 60s.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Static-Site-Generation]] · [[Web-Rendering-Strategies]]
|
||||
- 변형: [[Partial-Prerendering]] · [[Stale-While-Revalidate]] · [[Edge-SSR]]
|
||||
- 응용: [[Next.js]] · [[Vercel]] · [[Headless-CMS]]
|
||||
- Adjacent: [[CDN]] · [[React-Server-Components]] · [[Island Architecture]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: revalidate strategy 의 design, webhook handler 의 generate, cache tag 의 schema 의 propose.
|
||||
**언제 X**: 매 personalized content 의 cache key 의 design (PII leak risk — human review 필수).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Per-user ISR**: cookie/auth-dependent page 의 ISR → cross-user data leak.
|
||||
- **Tag explosion**: 매 query 의 unique tag → 매 cache 의 fragmentation.
|
||||
- **No fallback**: `fallback: false` + dynamic params → 404 의 surprise.
|
||||
- **Webhook 의 unsecured**: secret 의 X → revalidate 의 abuse 의 origin DoS.
|
||||
- **Long `revalidate`**: 1-day window 의 stale price → 매 revenue loss.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Next.js 15 docs, Vercel ISR blog 2020-2025).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Next.js ISR 의 full content |
|
||||
|
||||
Reference in New Issue
Block a user