← Lessons

quiz vs the machine

Gold1360

Frontend

Lazy Loading Routes

Split route code into chunks loaded on demand so the initial bundle stays small.

5 min read · core · beat Gold to climb

What it is

Lazy loading defers downloading a route's code until the user actually navigates there. The bundler creates a separate chunk per route, and the router requests it on demand.

Why split

  • The initial bundle ships only what the first screen needs.
  • Rarely visited routes like admin panels never load for most users.
  • Time to interactive improves because less JavaScript parses up front.

The flow

  • A dynamic import marks a route as a split point.
  • On navigation the router fetches the chunk over the network.
  • While loading, a fallback such as a spinner shows.

The cost

The first visit to a lazy route waits for a network round trip. Mitigate this by prefetching likely routes during idle time and by showing a meaningful loading state.

Why it matters

Lazy loading trades a small per route delay for a much faster first paint, which is the metric users feel most on initial load.

Key idea

Lazy loading splits routes into chunks fetched on demand, shrinking the initial bundle at the cost of a one time load when first visited.

Check yourself

Answer to earn rating on the learn ladder.

1. What does lazy loading defer?

2. A good way to hide the first visit network delay is to