Hoai-Nho-Logo

/

Blog

AboutProjectsBlogContact

All topics

Architecture & Design

Architecture & Design
Discover cutting-edge architecture and design ideas. Explore innovative projects, modern interior design trends, sustainable architecture, and creative design solutions to inspire your next project.aws saa-c03
AWS

Explore best practices, tutorials, case studies, and insights on leveraging AWS’s vast ecosystem to build, deploy, and manage applications in the cloud

Design patterns

The Design Pattern category explores reusable solutions to common software design challenges, helping developers write efficient, maintainable, and scalable code

Docker
Explore essential Docker tutorials and resources. Find helpful tips, best practices, and tools to master containerization and improve your deployment workflow.
Security

The Security category focuses on best practices, tools, and frameworks essential for protecting applications, data, and infrastructure in an increasingly digital world

SSL license expired?

Ultimate Guide to Renewing SSL Certificates: Secure Your Website in 2024

Ensure your website stays secure! 🔒 Learn how to check, renew, and manage your SSL certificate to prevent security risks and downtime. Follow our step-by-step guide with best practices to keep your HTTPS protection active in 2024!

CSS

Database

Database
Find easy-to-follow guides on database SQL, NoSQL, PostgreSQL, and MySQL. Learn how to make databases that are fast and work well. Get tips to improve your skills. database
MySQL
Discover essential database guides covering SQL, NoSQL, and best practices. Get tips and performance benchmarks to improve your data management skills.
NoSQL
Discover essential database guides covering SQL, NoSQL, and best practices. Get tips and performance benchmarks to improve your data management skills.
PostgreSQL
Explore comprehensive PostgreSQL tutorials and resources. Find helpful tips, best practices, and performance benchmarks to enhance your database skills.
Search topic

LIKE vs Full-Text Search: SQL Performance and Use Cases

Explore the differences between SQL’s LIKE operator and Full-Text Search. Learn their syntax, performance, use cases, and advanced features for optimizing database queries

Generation

Interview Question

NodeJS

NodeJS
Explore beginner to advanced tutorials on JavaScript and TypeScript. Find helpful tips, best practices, and tools to create powerful web applications. typescript_vs_javascript
Javascript/Typescript
Learn JavaScript and TypeScript with easy guides. Discover tips, best practices, and tools to build efficient web applications quickly.
tripple-cache

🚀 Triple-Layered Web Caching Strategy: How Memory, IndexedDB and HTTP Cache Improved Speed by 96%

Discover how to accelerate your website through our powerful triple-layered caching strategy combining Memory Cache, IndexedDB, and HTTP Cache. Detailed guidance from theory to practice helps reduce page load time by up to 96%, improve user experience, and optimize performance across all devices.


© 2025 Hoai Nho. All rights reserved.

ContactGitHubLinkedIn
  1. Home
  2. /Blog
  3. /Mastering 7 Types of Loading in Frontend Development: Best Practices and Examples

Mastering 7 Types of Loading in Frontend Development: Best Practices and Examples

Explore the 7 key types of loading in frontend development, including eager, lazy, code splitting, skeleton, progressive, infinite scrolling, and shimmer loading. Learn how each works, why they matter, best practices, and React.js code examples to optimize your web performance

Loading cover image
Hoài Nhớ@hoainho
December 04, 2024
|

3 min read

|

188 Views

Share:

1. Eager Loading

Eager loading fetches resources or data immediately when the application or page is rendered. It works by downloading resources like images, scripts, or data requests as soon as the browser encounters them during page load. This is critical for above-the-fold content or essential functionality.

Why Use It:

To ensure critical resources are available immediately and to avoid delays in rendering key content.

Best Practices:

• Use eager loading only for critical resources.

• Avoid using it for large or non-essential resources to prevent slowing down the initial page load.

React.js Code Example:

import React from "react";

const EagerLoadedImage = () => {
  return (
    <img
      src="/images/hero.jpg"
      alt="Hero"
      style={{ width: "100%", height: "auto" }}
    />
  );
};

export default EagerLoadedImage;

2. Lazy Loading

Lazy loading delays the loading of resources until they are needed, such as when they are scrolled into view. It works by using browser APIs like IntersectionObserver or native attributes (loading=”lazy”) to load resources only when they become visible.

image-1-1024x683 Mastering 7 Types of Loading in Frontend Development: Best Practices and Examples

Why Use It:

To improve initial load time and reduce bandwidth usage by loading resources only when necessary.

Best Practices:

• Use lazy loading for images, videos, or components that aren’t visible above the fold.

• Combine with responsive loading techniques for better performance.

React.js Code Example:

import React, { useState, useEffect } from "react";

const LazyLoadedImage = () => {
  const [isVisible, setIsVisible] = useState(false);
  const imgRef = React.useRef();

  useEffect(() => {
    const observer = new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting) {
        setIsVisible(true);
      }
    });

    if (imgRef.current) {
      observer.observe(imgRef.current);
    }

    return () => {
      if (imgRef.current) {
        observer.unobserve(imgRef.current);
      }
    };
  }, []);

  return (
    <div ref={imgRef} style={{ minHeight: "300px" }}>
      {isVisible && (
        <img src="/images/lazy-image.jpg" alt="Lazy" style={{ width: "100%" }} />
      )}
    </div>
  );
};

export default LazyLoadedImage;

3. Code Splitting

Code splitting divides your code into smaller chunks that are loaded on demand rather than in one large bundle. It works using bundlers like Webpack or Vite that automatically split your JavaScript files into smaller bundles.

Why Use It:

To reduce the size of the initial load and improve performance, especially for large applications.

Best Practices:

• Use dynamic imports for routes or components that aren’t needed during the initial load.

• Optimize with React’s React.lazy and Suspense for a seamless user experience.

React.js Code Example:

import React, { Suspense, lazy } from "react";

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

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

export default App;

4. Skeleton Loading

Skeleton loading uses a placeholder to mimic the structure of the content being loaded. It works by displaying a skeleton UI that disappears when the actual content is rendered.

image-1024x575 Mastering 7 Types of Loading in Frontend Development: Best Practices and Examples

Why Use It:

To improve perceived performance and provide a better user experience during loading states.

Best Practices:

• Use skeleton loading for components or data that take longer to load, such as user profiles or images.

• Keep the skeleton design simple and visually similar to the final content.

React.js Code Example:

import React, { useState, useEffect } from "react";

const SkeletonLoader = () => {
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    const timer = setTimeout(() => setIsLoading(false), 2000);
    return () => clearTimeout(timer);
  }, []);

  return isLoading ? (
    <div className="skeleton" style={{ width: "100%", height: "200px", background: "#ddd" }} />
  ) : (
    <img src="/images/content.jpg" alt="Content" style={{ width: "100%" }} />
  );
};

export default SkeletonLoader;

5. Progressive Loading

Progressive loading involves loading resources in stages, such as downloading lower-quality images first and then replacing them with higher-quality versions. It works by using techniques like progressive JPEGs or chunked data transfer.

Why Use It:

To provide users with partial content quickly, improving the perceived loading speed.

Best Practices:

• Use progressive images for media-heavy pages.

• Combine with lazy loading to load higher-quality resources as needed.

React.js Code Example:

import React, { useState } from "react";

const ProgressiveImage = ({ lowResSrc, highResSrc }) => {
  const [loaded, setLoaded] = useState(false);

  return (
    <div>
      <img
        src={lowResSrc}
        alt="Low Res"
        style={{ filter: "blur(10px)", position: "absolute" }}
      />
      <img
        src={highResSrc}
        alt="High Res"
        onLoad={() => setLoaded(true)}
        style={{ opacity: loaded ? 1 : 0, transition: "opacity 0.5s" }}
      />
    </div>
  );
};

export default ProgressiveImage;

6. Infinite Scrolling

Infinite scrolling loads content continuously as users scroll down the page. It works by dynamically fetching and appending new data to the DOM when the user reaches the bottom of the page.

image-3 Mastering 7 Types of Loading in Frontend Development: Best Practices and Examples

Why Use It:

To improve user experience in applications with large datasets, like social media feeds or e-commerce.

Best Practices:

• Use for content-heavy pages where users expect continuous scrolling.

• Implement proper cleanup to avoid performance issues.

React.js Code Example:

import React, { useState, useEffect } from "react";

const InfiniteScroll = ({ fetchData }) => {
  const [data, setData] = useState([]);

  useEffect(() => {
    const handleScroll = () => {
      if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
        fetchData().then(newData => setData(prev => [...prev, ...newData]));
      }
    };

    window.addEventListener("scroll", handleScroll);
    return () => window.removeEventListener("scroll", handleScroll);
  }, [fetchData]);

  return (
    <ul>
      {data.map((item, index) => (
        <li key={index}>{item}</li>
      ))}
    </ul>
  );

7. Shimmer Loading

Shimmer loading shows an animated gradient placeholder while content is being loaded. It works by displaying shimmering effects to simulate loading activity.

image-2 Mastering 7 Types of Loading in Frontend Development: Best Practices and Examples

Why Use It:

To create a more dynamic and visually appealing loading experience.

Best Practices:

• Use for components like cards or lists to keep the user engaged.

• Ensure the shimmer animation is lightweight and doesn’t hinder performance.

React.js Code Example:

import React from "react";

const ShimmerLoader = () => {
  return (
    <div
      style={{
        width: "100%",
        height: "200px",
        background: "linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%)",
        backgroundSize: "200% 100%",
        animation: "shimmer 1.5s infinite",
      }}
    />
  );
};

export default ShimmerLoader;


Tags:
Best PracticesUIUXWebOptimization
Written by

author
Hoài Nhớ

Hoài Nhớ

@Hoài Nhớ
Best PracticesUIUXWebOptimization

Table of Contents

    References posts

    🚀 Triple-Layered Web Caching Strategy: How Memory, IndexedDB and HTTP Cache Improved Speed by 96%

    Discover how to accelerate your website through our powerful triple-layered caching strategy combining Memory Cache, IndexedDB, and HTTP Cache. Detailed guidance from theory to practice helps reduce page load time by up to 96%, improve user experience, and optimize performance across all devices.

    Hoài Nhớ
    Redux Thunk vs Redux Saga: A Deep Dive into Strengths, Weaknesses, and Hidden Pitfalls

    This article explores the core differences between Redux Thunk and Redux Saga, highlighting their strengths, weaknesses, and best use cases. Whether you’re building a small application or managing complex asynchronous workflows, understanding these middleware options will help you make the right choice for your Redux architecture.

    Hoài Nhớ
    🚀 React 19 Deep Dive: A Senior Engineer’s Practical Guide to New Hooks

    An in-depth analysis of React 19’s new hooks from a 20-year veteran engineer’s perspective. Learn practical implementation strategies, best practices, and real-world use cases for use(), useFormState(), useFormStatus(), and useOptimistic() hooks.

    Hoài Nhớ
    Related Posts

    tripple-cache
    FrontendOptimizationIndexedDB
    🚀 Triple-Layered Web Caching Strategy: How Memory, IndexedDB and HTTP Cache Improved Speed by 96%

    Discover how to accelerate your website through our powerful triple-layered caching strategy combining Memory Cache, IndexedDB, and HTTP Cache. Detailed guidance from theory to practice helps reduce page load time by up to 96%, improve user experience, and optimize performance across all devices.

    Hoài Nhớ
    Redux Thunk and Saga
    Redux SagaRedux Thunk
    Redux Thunk vs Redux Saga: A Deep Dive into Strengths, Weaknesses, and Hidden Pitfalls

    This article explores the core differences between Redux Thunk and Redux Saga, highlighting their strengths, weaknesses, and best use cases. Whether you’re building a small application or managing complex asynchronous workflows, understanding these middleware options will help you make the right choice for your Redux architecture.

    Hoài Nhớ
    Breakings NewsReact19
    🚀 React 19 Deep Dive: A Senior Engineer’s Practical Guide to New Hooks

    An in-depth analysis of React 19’s new hooks from a 20-year veteran engineer’s perspective. Learn practical implementation strategies, best practices, and real-world use cases for use(), useFormState(), useFormStatus(), and useOptimistic() hooks.

    Hoài Nhớ

    Subscribe to our newsletter

    Get the latest posts delivered right to your inbox