Inferensys

Glossary

Code Splitting

Code splitting is a technique in JavaScript bundlers that breaks a large application bundle into smaller, dynamically loaded chunks, reducing the initial JavaScript payload and improving page load performance.
Developer working on RAG retrieval system, document chunks visible on screen, technical workspace with code editor.
BUNDLE ARCHITECTURE

What is Code Splitting?

Code splitting is a JavaScript bundling technique that decomposes a large application bundle into smaller, dynamically loaded chunks, reducing the initial payload size and improving page load performance.

Code splitting is the process of breaking a monolithic JavaScript bundle into multiple smaller chunks that can be loaded on demand or in parallel. Rather than forcing the browser to download, parse, and execute an entire application before rendering, bundlers like Webpack, Rollup, and Turbopack identify logical split points—typically at route boundaries or component-level imports—and generate separate files. This directly reduces the Time to Interactive (TTI) and First Input Delay (FID) by deferring non-critical code until it is actually required by user interaction.

Modern frameworks implement code splitting through dynamic import() statements, which return a promise and signal to the bundler that the imported module should be extracted into a separate chunk. React uses React.lazy() with Suspense boundaries, while Next.js applies automatic route-based splitting. Advanced strategies include vendor splitting to isolate third-party libraries with low update frequency, maximizing long-term browser caching, and prefetching chunks during idle time to mask latency when the user eventually navigates to a new route.

Core Mechanisms

Key Features of Code Splitting

Code splitting is a fundamental optimization technique that transforms a monolithic JavaScript bundle into smaller, on-demand chunks. By deferring non-critical code, it directly reduces the time to interactive and improves the user experience.

01

Entry Point Splitting

The most basic form of splitting, where a bundler like Webpack or Vite creates separate bundles for each entry point defined in the configuration. This is ideal for multi-page applications where distinct pages have entirely different dependency graphs. The bundler analyzes the dependency tree from each entry file and outputs independent chunks, ensuring a page only loads the JavaScript it strictly requires.

Multi-Page
Primary Use Case
02

Dynamic Imports

The import() syntax acts as a split point, returning a Promise that resolves to a module. Unlike static imports, this allows developers to explicitly define where the application should defer loading. This is the foundation for loading components on user interaction (e.g., opening a modal) or routing to a specific view, preventing heavy utility libraries from blocking the initial render.

import()
Syntax
03

Vendor Chunking

A strategy that separates application code from third-party dependencies (frameworks, utility libraries). By extracting a vendor chunk, the browser can cache these large, infrequently changing libraries independently. When application logic updates, the user only re-downloads the small application bundle, not the entire framework, drastically improving long-term caching and repeat-visit performance.

Long-Term
Caching Strategy
04

Route-Based Splitting

A pattern tightly integrated with client-side routers (like React Router or Vue Router). Components are loaded dynamically only when a user navigates to a specific route. This prevents the browser from parsing and executing the code for an admin dashboard or settings panel during the initial homepage load, keeping the main-thread execution cost minimal until the feature is explicitly requested.

Lazy Routes
Implementation
05

Preloading & Prefetching

The predictive side of code splitting. By injecting <link rel='preload'> or <link rel='prefetch'> tags, the browser can fetch high-priority chunks before they are explicitly called. Preload fetches a resource needed for the current navigation, while Prefetch downloads resources for future navigations during browser idle time, making subsequent page transitions feel instant.

Idle Time
Fetch Window
06

Common Chunk Extraction

A deduplication mechanism that prevents the same module from being included in multiple bundles. Tools like SplitChunksPlugin in Webpack analyze the dependency graph to identify shared code (e.g., a utility function used by two lazy-loaded routes) and automatically extract it into a shared, asynchronous chunk. This reduces total bytes shipped and prevents redundant code execution.

Deduplication
Core Goal
CODE SPLITTING

Frequently Asked Questions

Clear, technical answers to the most common questions about reducing JavaScript bundle sizes and improving load performance through code splitting.

Code splitting is a bundling technique that breaks a large JavaScript application into smaller, asynchronously loaded chunks rather than delivering a single monolithic file to the browser. It works by identifying split points in the application—typically at route boundaries, component boundaries, or conditional logic—where the bundler (such as Webpack, Rollup, or Turbopack) generates separate output files. These chunks are then fetched on demand using dynamic import() statements, which return a Promise that resolves when the module is loaded. The browser's native ES module system or bundler runtime handles dependency resolution, ensuring shared modules are extracted into common chunks to avoid duplication. The result is a dramatically smaller initial payload, as users only download the code required for the current view, with additional functionality streamed in as they navigate.

BUNDLE OPTIMIZATION TECHNIQUES

Code Splitting vs. Lazy Loading vs. Tree Shaking

A comparison of three distinct JavaScript optimization strategies that reduce initial payload size, each operating at a different phase of the build and runtime lifecycle.

FeatureCode SplittingLazy LoadingTree Shaking

Primary objective

Decompose bundle into smaller chunks loaded on demand

Defer resource loading until needed by user interaction

Eliminate dead code from the final bundle

Execution phase

Build-time split, runtime fetch

Runtime

Build-time (static analysis)

Trigger mechanism

Dynamic import() statement

Intersection Observer or user event

Static import/export analysis

Works with CommonJS (require)

Requires ES module syntax

Reduces initial JavaScript payload

Reduces total JavaScript shipped

Typical bundle size reduction

50-70% of initial load

30-60% of below-fold resources

10-40% of unused exports

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.