Free ATS Friendly Resume Builder Online

Create Your Resume

Resume Builder

Resume Maker

Resume Templates

Resume PDF Download

Create Your Resume is a free online resume builder that helps job seekers create professional, ATS friendly resumes in minutes. Easily build, customize, and download modern resume templates in PDF format.

Our resume maker is designed for freshers and experienced professionals looking to create job-ready resumes. Choose from multiple resume templates, customize sections, and generate ATS optimized resumes online for free.

Create resumes for IT jobs, software developers, freshers, experienced professionals, managers, and students. This free resume builder supports CV creation, resume PDF download, and online resume editing without signup.

Back to React Js
Lesson 38 of 59

What Is Lazy Loading in React? How React.lazy and Suspense Work to Load Components Efficiently

Lazy loading in React is a performance optimization technique that loads components only when they are needed, reducing initial bundle size and improving application load time. React provides built-in support for lazy loading through React.lazy and Suspense, enabling developers to split code and show fallback UIs during loading. This guide explains what lazy loading is, how React.lazy and Suspense work internally, and how to implement them correctly. With real-world examples, code snippets, best practices, and common pitfalls, this article helps developers build faster, scalable, and production-ready React applications.

What Is Lazy Loading in React?

Lazy loading is a technique where components are loaded only when they are required instead of being bundled and downloaded during the initial page load.

This reduces the amount of JavaScript sent to the browser and improves performance, especially for large applications.

Applications with multiple workflows such as interactive web platforms benefit greatly from lazy loading.

Why Lazy Loading Is Important

  • Smaller initial bundle size
  • Faster first load
  • Better performance on slow networks
  • Improved Core Web Vitals

What Is React.lazy?

React.lazy is a built-in function that allows you to dynamically import a component. The component is loaded only when it is rendered for the first time.

Basic Example of React.lazy


import { lazy } from "react";

const Dashboard = lazy(() => import("./Dashboard"));

This creates a separate JavaScript chunk for the Dashboard component.

What Is Suspense?

Suspense is a React component that lets you display a fallback UI while a lazy-loaded component is being fetched.

Using Suspense with Lazy Components


import { Suspense } from "react";

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

The fallback UI is shown until the component finishes loading.

Lazy Loading with React Router


import { Routes, Route } from "react-router-dom";
import { Suspense, lazy } from "react";

const Home = lazy(() => import("./Home"));
const Profile = lazy(() => import("./Profile"));

function App() {
  return (
    <Suspense fallback={<div>Loading page...</div>}>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/profile" element={<Profile />} />
      </Routes>
    </Suspense>
  );
}

This pattern is common in applications with structured navigation, such as step-based user flows.

Lazy Loading with Protected Components


const Dashboard = lazy(() => import("./Dashboard"));

<Route
  path="/dashboard"
  element={
    <ProtectedRoute isAuthenticated={true}>
      <Dashboard />
    </ProtectedRoute>
  }
/>

This ensures sensitive components are loaded only for authorized users.

Real-World Example Scenario

Consider an application with:

  • Public landing pages
  • User authentication pages
  • Dashboards and settings

With lazy loading:

  • Public users don’t download dashboard code
  • Initial load is faster
  • Resources are used efficiently

These performance patterns are widely recommended in frontend optimization articles.

Common Mistakes

  • Using React.lazy without Suspense
  • Placing one global Suspense for everything
  • Lazy loading very small components unnecessarily
  • Not handling loading states properly

Best Practices & Special Notes

  • Lazy load at route or feature level
  • Use meaningful fallback UIs
  • Combine with route-based code splitting
  • Avoid over-splitting components

To validate understanding of lazy loading and Suspense behavior, scenario-based challenges on interactive learning platforms are very effective.

Final Takeaway

Lazy loading and Suspense are powerful tools for improving React application performance. By loading components only when needed and providing fallback UIs, you reduce bundle size, improve user experience, and build scalable, production-ready React applications.