Next.js Course
Next.js
/
Beginner

Lazy Loading

Definition

The general concept of delaying the loading of non-critical resources (like images, iframes, or JS components) until the user actually needs them.

Explain Like I'm New

If an article has 100 high-resolution photos, it is insane to force the user to download all 100 before they even start reading the first paragraph. Lazy loading tells the browser to only download the photos that are currently visible on the screen.

Real World Example

A YouTube clone where the video thumbnails at the bottom of the page aren't actually loaded until the user scrolls down to look at them.

Common Use Cases

  • •Image heavy sites
  • •Performance optimization

Interactive Example

import Image from 'next/image';

export default function Article() {
  return (
    <main>
      {/* 
        CRITICAL: The image at the top of the screen MUST have 'priority'. 
        This disables lazy loading and forces the browser to fetch it instantly.
      */}
      <Image 
        src="/hero-banner.jpg" 
        priority 
        alt="Hero"
        width={1000} height={500} 
      />

      <p>Lots of text...</p>
      <p>Lots of text...</p>
      <p>Lots of text...</p>

      {/* 
        Way down here, we let Next.js do its default lazy loading behavior.
        This image won't download until the user scrolls down to it.
      */}
      <Image 
        src="/footer-illustration.jpg" 
        alt="Illustration"
        width={400} height={400} 
      />
    </main>
  );
}

Interview Questions

basic

  • Does the Next.js `<Image>` component lazy load images by default?

intermediate

  • If an image is at the very top of the page (above the fold), should you lazy load it?

Flash Cards

Question

Lazy load by default?

Click to reveal answer
Answer

Yes! The `<Image>` component applies native browser lazy loading out of the box with zero configuration.

Question

Above the fold?

Click to reveal answer
Answer

NO! You should NEVER lazy load the main 'Hero' image at the top of the page. Lazy loading inherently delays the image request slightly. You want the top image to load instantly. You must add the `priority` prop to it.