Skip to main content
Web DevPerformance & OptimizationDiagramBeginner

Code Splitting

KO: 코드 스플리팅 (Code Splitting)·EN: Code Splitting·JA: コード分割(Code Splitting)

A bundler optimization that divides a monolithic JavaScript bundle into smaller route- or feature-based chunks loaded on demand

Table of Contents

Structure Diagram

Monolithic Bundle vs Code-Split Chunks Comparison
MonolithSingle Monolithic Bundle

Load app.js (2.4 MB) upfront

  • Initial DownloadDownloads unused admin/chart code
  • Parse & CompileLong main-thread blocking
  • Cache Efficiency1-line edit busts entire 2.4 MB cache
Split ChunksCode-Split Chunks

Lean route & vendor chunks

  • Initial DownloadLoads only active route (~180 KB)
  • Parse & CompileMuch faster TTI & INP
  • Cache EfficiencyUnchanged vendor chunks stay cached
Quick Answer

What is Code Splitting?

A bundler optimization that divides a monolithic JavaScript bundle into smaller route- or feature-based chunks loaded on demand. It is a core concept in Performance & Optimization within Web Dev.

Core Principles

As web apps grow, shipping a single multi-megabyte bundle.js stalls initial load because JavaScript must be downloaded, parsed, compiled, and executed on the main thread.

Code splitting uses dynamic import() syntax and bundler chunking rules to break an application into smaller bundles—by route, conditional feature, or stable third-party vendor—so the browser executes only what the current screen requires.

Practical Takeaways

  • Start with route-based splitting: Frameworks like Next.js and Vite split per route automatically so visitors never download code for pages they don't open.
  • Split heavy on-demand widgets: Isolate PDF viewers, rich editors, maps, and charting libraries behind dynamic import() and <Suspense> fallbacks.
  • Avoid over-splitting: Hundreds of tiny 2 KB chunks hurt gzip/brotli compression ratios and increase waterfall overhead. Tune bundler chunk thresholds sensibly.

Notable Examples

  • Multi-route SaaS platforms: Separate onboarding, billing, and admin dashboards into distinct chunks with long-term browser caching for shared vendor libraries.
  • Locale and feature-flag bundles: Download only the active language dictionary and enabled experiment modules.