Course contentsShow
← React
Lesson 1358 of 2,39634. Suspense FundamentalsFree lesson

Lazy vs Eager: When Each is Right

Decide when to split code with React.lazy() versus keeping components in the main bundle.

Lazy vs Eager: When Each is Right

You'll learn: How to decide whether to load a component lazily with React.lazy() or include it eagerly in your main bundle.

The Decision Framework

Not every component deserves code splitting. Eager loading (bundling everything together) and lazy loading (splitting with React.lazy()) each have their place, and choosing wrong can hurt performance instead of helping.

Think of it like packing for a trip: you keep essentials in your carry-on (eager), but pack bulky items you'll only need occasionally in checked luggage (lazy).

When to Lazy Load

Use React.lazy() when:

  • Heavy components used conditionally: modals, admin panels, editor interfaces
  • Route-based sections: entire pages users may never visit
  • Large third-party libraries: charting, video players, rich text editors
  • Low-priority features: settings panels, help documentation
  • Above-the-fold vs below-the-fold: content not immediately visible

When to Stay Eager

Keep components in the main bundle when they're:

  • Immediately visible on load: navigation, headers, hero sections
  • Small in size: a few KB won't justify split overhead
  • Used on every page: shared layouts, common UI components
  • Critical for first render: anything blocking initial content

The Cost of Lazy Loading

Each lazy boundary adds a network request, however brief. For tiny components or those always needed, this delay outweighs the benefit of a smaller initial bundle. You're trading startup cost for runtime latency.

Key Takeaway: Lazy load large, conditional, or route-specific components; eagerly load small, always-visible, or critical-path code. The right split improves perceived performance—the wrong one adds frustrating delays.