Component-Level Lazy Loading with Suspense
Component-Level Lazy Loading with Suspense
While route-based code splitting optimizes initial page navigation, enterprise single-page applications often contain heavy, rarely triggered UI components within a single page—such as rich-text editors, export modals, 3D Canvas visualizers, or interactive charting widgets. Component-level lazy loading defers loading these resource-heavy assets until the exact moment they are needed.
1. When to Split at the Component Level
Splitting every tiny button or input creates HTTP chunk request waterfall overhead. Reserve component-level splitting for components that meet at least one of these criteria:
- Heavy Dependencies: Modules importing libraries > 50 KB gzip (e.g., Monaco Editor, Quill, Chart.js, Three.js, PDF.js).
- Conditional Visibility: Modals, drawer overlays, tabs, and collapsibles that a majority of users might never open during a session.
- Below-the-Fold Content: Complex data tables or footer report generators positioned far below the initial viewport.
2. On-Demand Modal Lazy Loading Pattern
A canonical pattern is loading an interactive modal only after the user clicks an "Open Modal" trigger:
3. Tabbed Interface Lazy Loading
When users navigate complex dashboards with multiple tabs, loading inactive tabs synchronously wastes memory and bandwidth.
4. Fallback Layout Stability and Cumulative Layout Shift (CLS)
A critical hazard in component lazy-loading is Cumulative Layout Shift (CLS). If a component replaces a 0-pixel fallback with a 600-pixel card, the surrounding UI jumps abruptly, damaging user experience and Core Web Vitals.
Practice Quiz
Dynamic Imports and Prefetching Strategies
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Route-Based Code Splitting with React lazy | Dynamic Imports and Prefetching Strategies |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.