Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
21

Frontend System Design · Lesson 21 of 86 · 4 min

Module Bundling Basics

In an interview, explaining why we bundle shows you think about performance from first principles.

Your browser can't efficiently handle a thousand tiny JavaScript files. Each import could trigger a separate HTTP request, creating a network waterfall that kills your page load time. That’s the core problem.

Module bundling is the process of resolving all your import and export statements at build time, stitching the code together into a few optimized files—the "bundles"—that the browser can download efficiently.

From entry point to dependency graph

A bundler doesn't just guess which files to include. You give it a starting point, the "entry point," which is usually your main index.js or app.tsx.

From there, it reads the code and looks for import statements. For each one it finds, it follows the path to that module and adds it to a "dependency graph." It then inspects that module for its own imports and repeats the process recursively until every needed piece of code is mapped out.

This graph is the bundler's master plan. It represents every module your application uses—your own components, utility functions, and third-party libraries from node_modules.

In an interview, describing how a bundler builds this graph shows you understand the mechanics, not just the buzzwords. It's the foundation for every optimization that follows.

Transforming and optimizing the output

Once the dependency graph is built, the bundler processes each file and assembles the final output. This involves several key transformations.

Transpilation: Your source code might be TypeScript, JSX, or use modern JavaScript features not supported by all browsers. The bundler uses tools like Babel or tsc to transpile this code into a more compatible version, typically ES5 or ES6.

Loaders and Plugins: Bundlers can be configured to handle more than just JavaScript. "Loaders" teach the bundler how to process other file types. A CSS loader might handle @import rules, and an image loader might inline small images as Base64 strings or copy larger ones to the output directory.

Minification: The bundler removes all unnecessary characters from the code—whitespace, comments, newlines—to reduce file size without changing functionality. It also performs "uglification," renaming variables and functions to shorter names (e.g., calculateUserPermissions becomes a).

Tree Shaking: This is a critical optimization. The bundler analyzes the dependency graph to detect which exported functions or variables are actually imported and used. Any unused code is "shaken out" of the final bundle.

The trap: Tree shaking only works with ES Modules (import/export). If your project or a dependency uses CommonJS (require/module.exports), the bundler can't safely determine what's unused, and you may end up shipping dead code.

Here’s a simple example. You have two modules:

// src/greeting.js
export function greet(name) {
  return `Hello, ${name}!`;
}

export function farewell(name) {
  return `Goodbye, ${name}!`;
}
// src/app.js
import { greet } from './greeting'; // Only 'greet' is imported

const userName = 'Frontend Developer';
console.log(greet(userName));

The bundler sees that farewell is exported but never imported by app.js or any of its dependencies. The conceptual output would effectively be:

// dist/bundle.js (simplified)
function greet(name) {
  return `Hello, ${name}!`;
}

const userName = 'Frontend Developer';
console.log(greet(userName));

The farewell function is gone. For a library like Lodash, this can save hundreds of kilobytes.

Splitting the bundle for faster loads

A single, large bundle is better than a thousand small files, but it's still not ideal. A user might download a 2MB app.bundle.js on their first visit, even if they only need 200KB of it for the landing page.

This is where code splitting comes in.

Instead of creating one giant bundle, you can configure the bundler to create multiple smaller ones. A common strategy is route-based splitting. The bundler creates a small "main" bundle with core, app-wide logic, and then separate bundles for each page or major feature (e.g., profile.js, dashboard.js, settings.js).

When the user navigates to their profile page, the application dynamically loads the profile.js bundle just in time. This dramatically improves the initial page load time, which is a critical performance metric.

When asked to design a large-scale frontend application, mentioning code splitting is non-negotiable. It demonstrates you're thinking about user experience and performance at scale, not just developer convenience.

Try it

Create a new project using Vite (npm create vite@latest). Make two JS files: one that exports two functions, and another that imports and uses only one of them. Run npm run build and inspect the output file in the dist directory. Search for the name of the unused function; you shouldn't find it.

Next: You'll learn how to measure the performance impact of your bundle with Core Web Vitals: LCP, INP and CLS.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Props, State and Component Lifecycle

Next

Core Web Vitals: LCP, INP and CLS