Files
2nd/10_Wiki/Topic_General/General Knowledge/Code Splitting Lazy Loading.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

5.8 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-code-splitting-lazy-loading Code Splitting & Lazy Loading 10_Wiki/Topics verified self
P-REINFORCE-AUTO-B933B1
Code Splitting
Lazy Loading
none A 0.95 applied
web
performance
bundling
react
vite
2026-05-10 pending
language framework
typescript react+vite

Code Splitting & Lazy Loading

매 한 줄

"매 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.

매 핵심

매 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.

매 핵심 메커니즘

  • 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.

매 응용

  1. SaaS dashboard — /admin route 의 lazy chunk.
  2. E-commerce — checkout flow 만 separate bundle.
  3. Editor app (Notion-like) — markdown/code-editor lazy.

💻 패턴

패턴 1: React.lazy + Suspense

import { lazy, Suspense } from "react";
import { Routes, Route } from "react-router-dom";

const Dashboard = lazy(() => import("./pages/Dashboard"));
const Settings = lazy(() => import("./pages/Settings"));

export function App() {
  return (
    <Suspense fallback={<Skeleton />}>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/dashboard" element={<Dashboard />} />
        <Route path="/settings" element={<Settings />} />
      </Routes>
    </Suspense>
  );
}

패턴 2: Vite manual chunks

// vite.config.ts
import { defineConfig } from "vite";

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";
        }
      }
    }
  }
});

패턴 3: Preload on hover (intent-based prefetch)

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>;
}

패턴 4: Conditional dynamic import

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;
  }
}

패턴 5: React Server Component (RSC) split

// app/dashboard/page.tsx (Next.js 15+)
import { Suspense } from "react";
import { HeavyChart } from "./HeavyChart"; // server component

export default function Page() {
  return (
    <>
      <Header />
      <Suspense fallback={<ChartSkeleton />}>
        <HeavyChart />  {/* streamed independently */}
      </Suspense>
    </>
  );
}

패턴 6: Bundle analyzer pipeline

# Vite + rollup-plugin-visualizer
npm i -D rollup-plugin-visualizer
import { visualizer } from "rollup-plugin-visualizer";

export default defineConfig({
  plugins: [visualizer({ open: true, gzipSize: true })]
});

패턴 7: Module federation (micro-frontend)

// 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
  • 변형: Module Federation
  • 응용: React Server Components — 경계 의식
  • Adjacent: Vite · 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)