Skip to main content

How Lazy Loading Improves Modern Website Performance

Updated 9 min readMarkdown

Modern websites often contain large images, videos, scripts, embedded content, and interactive components. If everything loads at the same time, the browser may need to download far more data than the user actually needs at that moment.

This can make pages feel slow, especially on mobile devices or unstable network connections.

One useful technique for improving this situation is lazy loading.

Lazy loading means delaying the loading of non-essential resources until they are actually needed. When implemented correctly, it can reduce initial page weight, improve loading speed, and make websites feel more responsive.

What Is Lazy Loading?

Lazy loading is a performance optimization technique that postpones loading selected resources.

Instead of downloading every image or component immediately, the browser waits until the resource is close to becoming visible or until the user interacts with a feature.

A simplified flow looks like this:

Page Opens
   ↓
Load Critical Content
   ↓
User Scrolls
   ↓
Load Additional Resources

This approach is especially useful for long pages with many images or sections.

1. Why Loading Everything Immediately Can Be Inefficient

Imagine a page containing 30 images.

If all 30 images are downloaded as soon as the page opens, the browser may consume unnecessary bandwidth.

The user may only view the first five images.

Without lazy loading:

Page Load
   ↓
Image 1
Image 2
Image 3
...
Image 30

With lazy loading:

Page Load
   ↓
Visible Images

User Scrolls
   ↓
More Images Load

This reduces unnecessary network work during the initial page load.

2. Native Lazy Loading for Images

Modern browsers support native lazy loading for images.

A simple example is:

<img
  src="example.jpg"
  alt="Example image"
  loading="lazy"
/>

The loading="lazy" attribute tells the browser that the image does not need to load immediately.

This is one of the easiest ways to improve pages with many images.

However, important images near the top of the page should usually not be lazy-loaded.

For example, the main hero image may contribute to Largest Contentful Paint, so delaying it could make performance worse.

3. Critical Content Should Load First

Lazy loading works best when developers clearly separate critical and non-critical resources.

Critical content may include:

  • main heading;
  • primary text;
  • navigation;
  • hero image;
  • essential CSS.

Non-critical content may include:

  • images far below the fold;
  • embedded media;
  • secondary widgets;
  • optional scripts.

A good performance strategy is not simply:

Lazy-load everything.

It is:

Load the most important content first, then delay the rest.

This distinction is important for real-world performance.

4. Intersection Observer Makes Lazy Loading More Flexible

For more advanced use cases, JavaScript can detect when an element is approaching the viewport.

The Intersection Observer API is commonly used for this purpose.

Example:

const observer = new IntersectionObserver((entries) => {
  entries.forEach((entry) => {
    if (entry.isIntersecting) {
      console.log("Element is visible");
    }
  });
});

This allows developers to trigger actions when an element becomes visible.

Possible uses include:

  • loading images;
  • starting animations;
  • loading modules;
  • fetching additional content.

This approach is often more efficient than continuously checking scroll position.

5. Lazy Loading JavaScript Modules

Images are not the only resources that can be delayed.

JavaScript can also be loaded only when needed.

For example, a large chart library may not be necessary during the initial page load.

Instead of loading it immediately, the application can use dynamic imports.

Example:

button.addEventListener("click", async () => {
  const module = await import("./chart.js");
  module.renderChart();
});

The browser downloads the module only after the user interacts with the button.

This reduces the initial JavaScript bundle.

6. Code Splitting Works Well with Lazy Loading

Code splitting divides a large JavaScript bundle into smaller files.

Instead of:

app.js

containing the entire application, the build process may create:

home.js
search.js
dashboard.js
settings.js

Only the files needed for the current page are loaded.

This can improve:

  • startup time;
  • parsing time;
  • memory usage;
  • network efficiency.

Frameworks such as React, Vue, and other modern frontend tools often provide built-in patterns for code splitting.

7. Route-Based Lazy Loading

Single-page applications can benefit from route-based loading.

Suppose an application contains:

  • Home;
  • Articles;
  • Reports;
  • Settings.

There is little reason to download the Settings page code when the user only visits Home.

A better approach is:

User Opens Home
      ↓
Load Home Bundle

User Opens Reports
      ↓
Load Reports Bundle

This keeps the first load smaller.

For digital platforms such as JLPH, modular loading can be useful when a website contains multiple sections with different technical requirements.

8. Lazy Loading Embedded Content

Embedded content can be expensive.

Examples include:

  • maps;
  • video players;
  • external widgets;
  • interactive visualizations.

These components may load additional JavaScript, stylesheets, and network requests.

A useful strategy is to display a lightweight placeholder first.

For example:

Video Thumbnail
      ↓
User Clicks
      ↓
Load Video Player

This reduces initial page work.

It also gives the user more control over when heavy content loads.

9. Lazy Loading Can Reduce Bandwidth Usage

Lazy loading is not only about speed.

It can also reduce data usage.

This matters for users on mobile connections.

Suppose a page contains:

Total Image Size: 12 MB

But the user only scrolls through half the page.

Without lazy loading, the full 12 MB may still be downloaded.

With lazy loading, only a portion may be transferred.

This can improve efficiency for both the user and the website.

10. Lazy Loading and Core Web Vitals

Lazy loading can influence several performance metrics.

Largest Contentful Paint

Important above-the-fold images should load quickly.

If a major visual element is lazy-loaded, LCP may become slower.

Interaction to Next Paint

Reducing unnecessary JavaScript can improve responsiveness.

Cumulative Layout Shift

Lazy-loaded images should have width and height information.

For example:

<img
  src="photo.jpg"
  width="800"
  height="500"
  loading="lazy"
  alt="Example"
/>

Providing dimensions helps the browser reserve space before the image loads.

This reduces layout movement.

11. Avoiding Layout Shift

A common mistake is loading images without reserving space.

Before loading:

Text
Text
Text

After the image appears:

Text
Image
Text
Text

The content suddenly moves.

This creates a poor experience.

Developers can avoid this by using:

  • width and height attributes;
  • aspect-ratio;
  • fixed placeholders.

Example:

.image-wrapper {
  aspect-ratio: 16 / 9;
}

This allows the browser to reserve the correct amount of space.

12. Lazy Loading APIs and Data

The same principle can be applied to API requests.

Not every section of a dashboard needs data immediately.

For example:

Page Opens
   ↓
Load Summary Data

User Opens Analytics Tab
   ↓
Fetch Analytics Data

This reduces unnecessary backend requests.

It can also improve initial render time.

However, developers should avoid making users wait unnecessarily after every interaction.

A balance is needed between delayed loading and perceived responsiveness.

13. Prefetching Can Complement Lazy Loading

Lazy loading delays resources.

Prefetching does almost the opposite.

It downloads resources that the browser expects may be needed soon.

For example:

<link rel="prefetch" href="/next-page.js">

A practical strategy is:

  • lazy-load content that may never be needed;
  • prefetch content that is likely to be needed soon.

This combination can improve navigation without increasing the initial workload too much.

14. Lazy Loading Should Be Tested on Real Devices

A page that feels fast on a developer's desktop may behave differently on:

  • older smartphones;
  • slower processors;
  • mobile networks;
  • different browsers.

Performance testing should include realistic conditions.

Useful tools include:

  • browser developer tools;
  • Lighthouse;
  • network throttling;
  • CPU throttling;
  • real user monitoring.

This helps teams understand whether lazy loading actually improves the experience.

15. Too Much Lazy Loading Can Create Problems

Lazy loading is useful, but overusing it can make a website feel fragmented.

Possible issues include:

  • visible delays while scrolling;
  • empty placeholders;
  • frequent loading indicators;
  • delayed interactions.

For example, loading every small icon separately would create unnecessary complexity.

Developers should apply lazy loading to resources that are genuinely expensive or unlikely to be needed immediately.

16. A Practical Loading Strategy

A balanced loading strategy might look like this:

Initial Load
   ↓
HTML
Critical CSS
Main Heading
Hero Image
Essential JavaScript

After Initial Load
   ↓
Secondary Images
Optional Modules
Additional Content

On Interaction
   ↓
Charts
Video Players
Advanced Features

This keeps the first experience fast while still allowing the website to provide richer features later.

17. Measure Before and After

Performance optimization should be based on measurement.

Before adding lazy loading, record metrics such as:

  • total transferred bytes;
  • number of requests;
  • LCP;
  • JavaScript size;
  • load time.

Then measure again after implementation.

Example:

Metric Before After
Initial Transfer 4.8 MB 2.1 MB
Initial Requests 62 34
LCP 3.1 s 2.4 s
JavaScript Loaded 780 KB 430 KB

This makes it easier to confirm whether the change created a real improvement.

Conclusion

Lazy loading is one of the most practical techniques for improving modern website performance.

By delaying non-essential images, scripts, modules, and embedded content, developers can reduce the amount of work required during the initial page load.

For digital brands such as JLPH, these techniques can help support websites that are lighter, more responsive, and easier to use across different devices.

The key is to apply lazy loading selectively.

Critical content should appear quickly, while secondary resources can wait until they are needed.

When combined with code splitting, caching, responsive images, and performance monitoring, lazy loading becomes a simple but powerful part of a broader web optimization strategy.

About the author

  • WINMYR ialah platform Malaysia yang menyediakan kandungan hiburan digital dan maklumat platform permainan dalam talian.

No comments yet. Be the first to comment.