Skip to content

Lazy Loading

In one line

Lazy loading means deferring the loading of a component until it is actually rendered, reducing the initial bundle size.

In simple words

Lazy loading (code splitting) means a component's code is not included in the main bundle — it is fetched on demand when the component is first rendered. This reduces the initial JavaScript payload and speeds up the first paint.

React provides React.lazy() for lazy-loading components and <Suspense> for showing a fallback while the code loads. const Admin = React.lazy(() => import('./Admin')) creates a component that is loaded on first render. Wrap it in <Suspense fallback={<Spinner />}>... to show a loading indicator.

Lazy loading is most useful for route-level components (pages the user may never visit), large modals, or heavy features. The trade-off is a slight delay when the component is first needed, but the initial load is much faster.

Example

jsx
const AdminPanel = React.lazy(() => import("./AdminPanel"));

function App() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <AdminPanel />
    </Suspense>
  );
}

AdminPanel's code is in a separate chunk. When it first renders, React shows the fallback while the chunk loads, then renders the component.

Related terms

Related Resources

Related Lessons

  • Lazy Loading

    Learn React.lazy and Suspense for code splitting.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary