← Back to Index

Lazy Loading

FigureEager vs Lazy loading. Eager loads everything at start (slow). Lazy loads only what is visible (fast).

What is Lazy Loading?

Lazy loading is a performance optimization technique that delays the loading of resources until they are actually needed. Instead of loading all 50 images on a page immediately when the page loads, lazy loading loads only the images currently visible on the screen. As the user scrolls, additional images load just before they appear in the viewport.

This technique applies not only to images but also to:

  • Videos and iframes
  • JavaScript modules
  • Fonts
  • Any non-critical resources

The term "lazy" contrasts with "eager" loading, where everything loads immediately regardless of whether the user will see it.

Why Lazy Loading Matters for SEO

1. Faster Initial Page Load

By deferring non-critical resources, the browser can focus on loading content the user actually sees first. This dramatically improves:

Largest Contentful Paint (LCP): The main content renders faster because the browser is not downloading images below the fold.

First Contentful Paint (FCP): Something appears on screen sooner, reducing perceived loading time.

Time to Interactive (TTI): Less network and CPU usage means the page becomes interactive faster.

2. Better Core Web Vitals

Core Web Vitals directly impact search rankings. Lazy loading is one of the most effective techniques for improving these metrics, especially for image-heavy pages like:

  • E-commerce product listings
  • Portfolio galleries
  • Blog posts with many images
  • Image-heavy landing pages

3. Bandwidth Savings

Users who never scroll to the bottom of a page do not download images they will never see. This is particularly valuable for:

  • Mobile users on limited data plans
  • Users with slow connections
  • Pages with extensive content

4. Server Resource Optimization

Fewer simultaneous requests reduce server load and bandwidth costs. This becomes significant at scale with high-traffic websites.

Native Browser Lazy Loading

Modern browsers support native lazy loading through the loading attribute:

html
<img src="image.jpg" alt="Description" loading="lazy" />

Benefits of Native Lazy Loading

  • No JavaScript required
  • Browser-optimized implementation
  • Automatic threshold handling
  • Works even if JavaScript fails
  • Googlebot understands it natively

Browser Support

Native lazy loading is supported in Chrome, Edge, Firefox, Safari, and Opera. Older browsers simply ignore the attribute and load images normally (graceful degradation).

Implementing Lazy Loading

For Images

html
<!-- Lazy loaded image -->
<img
  src="product.jpg"
  alt="Product description"
  loading="lazy"
  width="400"
  height="300"
/>

For Iframes

html
<!-- Lazy loaded YouTube embed -->
<iframe
  src="https://www.youtube.com/embed/VIDEO_ID"
  loading="lazy"
  width="560"
  height="315"
></iframe>

JavaScript-Based Lazy Loading

For more control, use the Intersection Observer API:

javascript
const observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      const img = entry.target;
      img.src = img.dataset.src;
      observer.unobserve(img);
    }
  });
});

document.querySelectorAll('img[data-src]').forEach(img => {
  observer.observe(img);
});

SEO Risks and Best Practices

1. Never Lazy Load Above-the-Fold Content

The Mistake: Lazy loading the hero image or main content visible without scrolling.

The Impact: The browser delays loading the LCP element, severely hurting Core Web Vitals scores. Users see a blank space or placeholder before the main image loads.

The Fix: Always eagerly load content in the initial viewport:

html
<!-- Hero image - eager load (default behavior) -->
<img src="hero.jpg" alt="Hero" loading="eager" />

<!-- Below-fold images - lazy load -->
<img src="product1.jpg" alt="Product" loading="lazy" />

2. Ensure Googlebot Can See Images

The Mistake: Using JavaScript lazy loading libraries that hide image sources from the HTML.

The Impact: Googlebot may not discover or index your images because it cannot find the image URLs in the initial HTML.

The Fix: Use native lazy loading or ensure src attributes are present in HTML. With JavaScript solutions, use noscript fallbacks:

html
<img data-src="image.jpg" class="lazy" alt="Product" />
<noscript>
  <img src="image.jpg" alt="Product" />
</noscript>

3. Prevent Layout Shifts

The Mistake: Images load and push content around, causing Cumulative Layout Shift (CLS).

The Impact: Poor CLS scores hurt Core Web Vitals and user experience as content jumps unexpectedly.

The Fix: Always define explicit width and height:

html
<img
  src="image.jpg"
  alt="Description"
  loading="lazy"
  width="800"
  height="600"
/>

Or use CSS aspect-ratio:

css
img {
  aspect-ratio: 16 / 9;
  width: 100%;
  height: auto;
}

4. Provide Appropriate Placeholders

While images load, users should see something indicating content will appear:

  • Low-quality image placeholders (LQIP)
  • Blur-up effects
  • Skeleton loading states
  • Solid color backgrounds matching image tones

This improves perceived performance and reduces CLS.

Framework-Specific Implementation

Next.js

Next.js Image component handles lazy loading automatically:

jsx
import Image from 'next/image';

<Image
  src="/product.jpg"
  alt="Product"
  width={400}
  height={300}
  loading="lazy" // Default behavior for non-priority images
/>

Use priority for above-the-fold images:

jsx
<Image src="/hero.jpg" alt="Hero" priority />

WordPress

WordPress 5.5+ includes native lazy loading for images. Most themes and page builders also support lazy loading configuration.

React

Use libraries like react-lazy-load-image-component or implement with Intersection Observer for custom solutions.

Testing Lazy Loading

Chrome DevTools

  1. Open Network tab
  2. Throttle connection to Slow 3G
  3. Scroll the page and watch images load on demand
  4. Check that above-fold images load immediately

Lighthouse

Run a Lighthouse audit and check:

  • "Defer offscreen images" recommendation
  • LCP timing
  • CLS scores

Real User Monitoring

Track Core Web Vitals in production using Google Search Console or analytics tools to verify lazy loading improvements.

Common Lazy Loading Mistakes

Loading Too Aggressively

Starting to load images only when they enter the viewport creates visible loading delays. Load images slightly before they appear.

Using Heavy JavaScript Libraries

Large lazy loading libraries can negate performance benefits. Native lazy loading has zero JavaScript overhead.

Forgetting About Print Styles

Lazy-loaded images may not appear when users print pages. Consider loading all images for print media.

Not Testing Edge Cases

Test on slow connections, without JavaScript, and with various browsers to ensure robust implementation.