liveBook · Manning

Lazy initialization

As explained in Acing the Frontend Interview

Lazy loading defers loading a resource until it is needed.

Lazy loading defers loading a component until its route is accessed. In a modular React application, this reduces the initial bundle size while allowing business-domain features to load on demand. section 5.1

A route-level implementation combines:

Listing 5.1 Modular route application
const CheckoutApp = lazy(() => 
  import('../features/checkout/CheckoutApp')); #A
const UserProfileApp = lazy(() => 
  import('../features/profile/UserProfileApp'));
const ProductInventoryApp = lazy(
  () => import('../features/products/ProductInventoryApp')
);
const ModularRouteApp = () => {
  return (
    <BrowserRouter>
      <Suspense fallback={<div>Loading...</div>}> #B
        <nav #C
          style={{
            display: 'flex',
            gap: '10px',
            marginBottom: '20px',
          }}
        >
          <Link to="/checkout">Checkout</Link>
          <Link to="/profile">Profile</Link>
          <Link to="/products">Products</Link>
        </nav>
        <Routes> #D
          <Route path="/" #E
            element={<Navigate to="/products" replace />} /> 
          <Route path="/checkout/*" element={<CheckoutApp />} />
          <Route path="/profile/*" element={<UserProfileApp />} />
          <Route path="/products/*" element={<ProductInventoryApp />} />
          <Route path="*" element={<div>404: Page Not Found</div>} /> #F
        </Routes>
      </Suspense>
    </BrowserRouter>
  );
};

The example shows lazily imported checkout, profile, and product features, wrapped in Suspense and connected to domain routes. section 5.1

How Acing the Frontend Interview covers it

How deep it goes
Shows React.lazy, dynamic imports, and Suspense in route-level implementation, without detailing loading internals.
Examples
Uses checkout, profile, and product routes as independently loaded feature modules.
What you can do after
Apply via React.lazy and Suspense to load route components on demand.
How it connects
Connects code splitting with React Router and ES modules.

Also explained in

Compare how 12 books explain lazy initialization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.