[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
@@ -1,84 +1,192 @@
---
id: wiki-2026-0508-code-splitting-lazy-loading
title: Code Splitting Lazy Loading
title: Code Splitting & Lazy Loading
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-REINFORCE-AUTO-B933B1]
aliases: [P-REINFORCE-AUTO-B933B1, Code Splitting, Lazy Loading]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
tags: [auto-reinforced]
confidence_score: 0.95
verification_status: applied
tags: [web, performance, bundling, react, vite]
raw_sources: []
last_reinforced: 2026-04-20
github_commit: "[P-Reinforce] Continuous Worker - Code Splitting Lazy Loading"
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: unspecified
framework: unspecified
language: typescript
framework: react+vite
---
# [[Code Splitting Lazy Loading]]
# Code Splitting & Lazy Loading
## 📌 한 줄 통찰 (The Karpathy Summary)
> 지식 요약 정보 추출 중...
## 한 줄
> **"매 ship-only-what-you-execute"**. 매 Code Splitting 은 single bundle 을 route/component-bound chunk 로 분할하여 initial JS payload 의 minimization. Lazy Loading 은 매 chunk 를 user-interaction 시점에 fetch. 매 2026 의 standard 는 Vite + React.lazy + dynamic import + RSC (React Server Components) hybrid.
## 📖 구조화된 지식 (Synthesized Content)
본문 구조화 작업 중...
## 매 핵심
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
- **정책 변화:** General Knowledge 분야의 자동 자산화 수행.
### 매 split 차원
- **Route-based**: 매 page 의 lazy import — `/dashboard`, `/settings`.
- **Component-based**: 매 heavy widget (chart, code-editor) 의 deferred load.
- **Vendor split**: 매 third-party (React, lodash) 의 separate chunk → long-term cache.
- **Dynamic feature flag**: 매 A/B variant 의 gated import.
## 🔗 지식 연결 (Graph)
- Raw Source: [[00_Raw/2026-04-20/Code Splitting & Lazy Loading.md]]
---
### 매 핵심 메커니즘
- **Dynamic `import()`**: 매 ES module spec — Promise 반환.
- **Bundler chunk splitting**: Webpack/Vite 의 `splitChunks` heuristic.
- **HTTP/2 push 의 deprecation**: 매 modern preload + modulepreload 로 대체.
- **Streaming SSR + RSC**: 매 chunk 의 server-streamed delivery.
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### 매 응용
1. SaaS dashboard — `/admin` route 의 lazy chunk.
2. E-commerce — checkout flow 만 separate bundle.
3. Editor app (Notion-like) — markdown/code-editor lazy.
**언제 이 지식을 쓰는가:**
- *(TODO)*
## 💻 패턴
**언제 쓰면 안 되는가:**
- *(TODO)*
### 패턴 1: React.lazy + Suspense
```tsx
import { lazy, Suspense } from "react";
import { Routes, Route } from "react-router-dom";
## 🧪 검증 상태 (Validation)
const Dashboard = lazy(() => import("./pages/Dashboard"));
const Settings = lazy(() => import("./pages/Settings"));
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
## 🧬 중복 검사 (Duplicate Check)
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
## 🕓 변경 이력 (Changelog)
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
## 💻 코드 패턴 (Code Patterns)
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
```text
# TODO
export function App() {
return (
<Suspense fallback={<Skeleton />}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/settings" element={<Settings />} />
</Routes>
</Suspense>
);
}
```
## 🤔 의사결정 기준 (Decision Criteria)
### 패턴 2: Vite manual chunks
```ts
// vite.config.ts
import { defineConfig } from "vite";
**선택 A를 써야 할 때:**
- *(TODO)*
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("node_modules/react")) return "react-vendor";
if (id.includes("node_modules/@radix-ui")) return "radix";
if (id.includes("/src/charts/")) return "charts";
}
}
}
}
});
```
**선택 B를 써야 할 때:**
- *(TODO)*
### 패턴 3: Preload on hover (intent-based prefetch)
```tsx
function NavLink({ to, children }: { to: string; children: React.ReactNode }) {
const prefetch = () => {
if (to === "/dashboard") import("./pages/Dashboard");
};
return <Link to={to} onMouseEnter={prefetch} onFocus={prefetch}>{children}</Link>;
}
```
**기본값:**
> *(TODO)*
### 패턴 4: Conditional dynamic import
```tsx
async function loadChart(type: "line" | "bar" | "heatmap") {
switch (type) {
case "line": return (await import("./charts/Line")).default;
case "bar": return (await import("./charts/Bar")).default;
case "heatmap": return (await import("./charts/Heatmap")).default;
}
}
```
## ❌ 안티패턴 (Anti-Patterns)
### 패턴 5: React Server Component (RSC) split
```tsx
// app/dashboard/page.tsx (Next.js 15+)
import { Suspense } from "react";
import { HeavyChart } from "./HeavyChart"; // server component
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
export default function Page() {
return (
<>
<Header />
<Suspense fallback={<ChartSkeleton />}>
<HeavyChart /> {/* streamed independently */}
</Suspense>
</>
);
}
```
### 패턴 6: Bundle analyzer pipeline
```bash
# Vite + rollup-plugin-visualizer
npm i -D rollup-plugin-visualizer
```
```ts
import { visualizer } from "rollup-plugin-visualizer";
export default defineConfig({
plugins: [visualizer({ open: true, gzipSize: true })]
});
```
### 패턴 7: Module federation (micro-frontend)
```ts
// host vite.config.ts
import federation from "@originjs/vite-plugin-federation";
export default {
plugins: [
federation({
name: "host",
remotes: { checkout: "http://cdn/checkout/remoteEntry.js" },
shared: ["react", "react-dom"]
})
]
};
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Multi-page SPA | route-based React.lazy |
| Heavy single widget | component-level dynamic import |
| Multi-team monorepo | module federation |
| Server-rendered Next.js | RSC + Suspense streaming |
| Legacy Webpack 4 | upgrade to Vite/Webpack 5 first |
| Initial paint > 3s | bundle analyzer + manualChunks |
**기본값**: Vite + React.lazy(route) + intent-prefetch on hover.
## 🔗 Graph
- 부모: [[Web Performance]] · [[Bundlers]]
- 변형: [[Tree Shaking]] · [[Module Federation]]
- 응용: [[React Server Components]] · [[Next.js App Router]]
- Adjacent: [[Vite]] · [[Webpack]] · [[Rollup]] · [[esbuild]]
## 🤖 LLM 활용
**언제**: bundle analysis 의 chunk strategy 추천, lazy boundary 후보 식별, manualChunks rule 작성.
**언제 X**: 매 production runtime 의 dynamic decision — 매 bundler-time static analysis 의 영역.
## ❌ 안티패턴
- **Over-splitting**: 매 component 마다 lazy — 매 too many waterfalls. 매 100KB+ threshold.
- **Suspense boundary 의 미사용**: 매 React.lazy 의 fallback 없음 → throw.
- **Preload everything**: 매 idle prefetch 의 abuse — bandwidth waste.
- **Dynamic import in render**: 매 매 render 마다 import() 호출 → re-fetch.
## 🧪 검증 / 중복
- Verified (web.dev code-splitting docs, Vite docs, React.lazy spec, RFC#118).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — substantive content + 2026 stack (Vite, RSC, module federation) |