Check 06.19 · Performance and Core Web Vitals

Lazy-load offscreen content

Only load offscreen images, iframes and videos as the visitor scrolls near them, with loading lazy and the settings specific to each CMS and framework.

Priority
Important
Difficulty
Easy
Estimated time
30 min to 2 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

Lazy loading means downloading an image, an iframe or a video only when the visitor gets close to it while scrolling the page. The HTML loading="lazy" attribute is enough in the vast majority of cases, with no JavaScript library. The rule fits in two lines: everything below the first screen is deferred, nothing in the first screen is. Once this check is done, the initial load only downloads the media that are actually visible.

Why it matters

Without instructions, the browser downloads every image in the HTML at load time, including those in the footer that many visitors will never see. These requests share bandwidth with the CSS, the fonts and the main image: on a mobile connection, they delay what matters. An iframe is even worse, as it loads an entire document with its own scripts.

With loading="lazy", the browser holds the request back as long as the element is far from the visible area, then starts it as scrolling brings it closer, with a margin it adjusts itself.

As for search engines, two points to know:

  • Googlebot does not scroll the page or click. It renders the page in a very tall viewport, which triggers native lazy loading and scripts based on IntersectionObserver.
  • A script that waits for a scroll event (scroll) or an interaction never fires for Googlebot: the images, and any content loaded this way, remain invisible to indexing.

Native lazy loading is therefore the safest choice for SEO as well as for performance.

What it improves

  • Initial load Fewer requests and bytes competing with critical resources, and therefore a faster LCP (Largest Contentful Paint, the display of the largest visible element) on media-heavy pages. The effect is indirect.
  • Mobile data and costs Media that are never seen are never downloaded. Less bandwidth for the visitor, the server and the CDN.
  • Responsiveness Deferred iframes (videos, maps) do not run their scripts at load time, which relieves the main thread.
  • Rankings Indirect effect, through Core Web Vitals. Applied badly (main image deferred, content invisible to crawlers), the effect is negative.

How to check

Load the page without scrolling, then run the following in the console.

Offscreen images that are not deferred (to fix):

[...document.images]
  .filter((img) => img.loading !== 'lazy' && img.getBoundingClientRect().top > window.innerHeight)
  .map((img) => img.currentSrc || img.src);

First-screen images wrongly deferred (also to fix):

[...document.images]
  .filter((img) => img.loading === 'lazy' && img.getBoundingClientRect().top < window.innerHeight)
  .map((img) => img.currentSrc || img.src);

Compliant result: two empty arrays, at mobile width as well as desktop width.

Other checks:

  • Network tab, “Img” filter: after loading without scrolling, only the images at the top of the page are listed. New lines appear as you scroll.
  • Iframes: document.querySelectorAll('iframe:not([loading="lazy"])') lists those that load immediately.
  • Google's view: in Search Console, inspect the URL, run Test live URL and open the rendered HTML. The <img> tags at the bottom of the page must carry their real src. See test rendering in Search Console (opens in a new tab).

How to implement

Before you start

Target tags:

<img src="/images/atelier-800.webp" width="800" height="533"
     alt="Assembly station in the workshop" loading="lazy" decoding="async">

<iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID" width="560" height="315"
        title="Product demo" loading="lazy" allowfullscreen></iframe>

<video controls preload="none" poster="/images/demo-poster.webp" width="1280" height="720">
  <source src="/videos/demo.mp4" type="video/mp4">
</video>

Rules that apply everywhere:

CSS background images have no loading attribute. Defer them with a class added as they approach the visible area:

.promo {
  min-height: 320px;
  background-color: #f2f2f2;
  background-size: cover;
}

.promo.is-visible {
  background-image: url("/images/promo-1200.webp");
}
<section class="promo js-lazy-background">
  <h2>Offer of the month</h2>
</section>

<script>
  var backgroundObserver = new IntersectionObserver(function (entries) {
    entries.forEach(function (entry) {
      if (!entry.isIntersecting) {
        return;
      }

      entry.target.classList.add('is-visible');
      backgroundObserver.unobserve(entry.target);
    });
  }, { rootMargin: '200px' });

  document.querySelectorAll('.js-lazy-background').forEach(function (element) {
    backgroundObserver.observe(element);
  });
</script>

Warning: if you use a JavaScript lazy loading library (data-src attributes), check that it relies on IntersectionObserver and not on the scroll event, and check the rendered HTML in Search Console. Native lazy loading avoids this risk.

WordPress

Versions WordPress 6.4 and later (checked on 7.1).

WordPress adds loading="lazy" to images that have dimensions (since version 5.5) and to iframes (since 5.7), sparing the first images in the content. In principle there is nothing to enable. Points to check:

  • Images hard-coded in the theme (<img src="..."> in a PHP file): they escape the mechanism. Use wp_get_attachment_image() or add the attribute by hand.
  • Images without dimensions: WordPress does not defer them. Fill in width and height.
  • Exclude a specific image from lazy loading, for example with a no-lazy CSS class:
add_filter('wp_img_tag_add_loading_attr', function ($value, string $image) {
    if (str_contains($image, 'no-lazy')) {
        return false;
    }

    return $value;
}, 10, 2);

Plugins (WP Rocket's Media tab, LiteSpeed Cache's Page Optimization > Media Settings, Perfmatters, Autoptimize) add their own script-based lazy loading. They are useful for what native lazy loading does not cover: CSS backgrounds and replacing YouTube iframes with a preview image. Do not stack two plugins on the same feature, and check that the main image is excluded.

Shopify

Versions Online Store 2.0 themes, Liquid, all Shopify plans, November 2026.

The image_tag filter automatically defers images in sections located further down the page. In a product grid, decide based on position:

{%- for product in collection.products -%}
  {%- if forloop.index <= 4 -%}
    {%- assign image_loading = 'eager' -%}
  {%- else -%}
    {%- assign image_loading = 'lazy' -%}
  {%- endif -%}

  {{ product.featured_image | image_url: width: 600 | image_tag: loading: image_loading, alt: product.title }}
{%- endfor -%}

Images inserted into product descriptions and pages through the rich text editor do not go through image_tag: add the attribute in the editor's HTML if there are many of them.

PrestaShop

Versions PrestaShop 8 and 9, Classic and Hummingbird themes.

The Classic and Hummingbird themes shipped with PrestaShop 8 and 9 already put loading="lazy" on product thumbnails (templates/catalog/_partials/miniatures/product.tpl in Classic, product-image.tpl in the same folder for Hummingbird). On an older or custom theme, add the attribute in this template and in the templates of modules that display images below the first screen (brands, related products, blog). Images entered in CMS pages and descriptions need the attribute in the editor. Clear the cache in Advanced Parameters > Performance.

Magento

Versions Magento Open Source and Adobe Commerce 2.4 (2.4.6 to 2.4.9), Luma and Blank themes.

In Luma and Blank, the product list thumbnails (Magento_Catalog/templates/product/image_with_borders.phtml) already carry loading="lazy". Check the HTML of category pages with a third-party or custom theme, and add the attribute in a template override if needed. This template also defers the first row: if it is in the first screen, override the template to exclude it. Images in CMS blocks and Page Builder are set in the content's HTML. Flush the caches (bin/magento cache:flush).

Drupal

Versions Drupal 10 and 11.

Drupal adds loading="lazy" to images rendered by an image field as soon as their dimensions are known. Two settings complement this:

  • Per field: Structure > Content types > your type > Manage display, the image field's gear icon, image loading setting (lazy or eager).
  • Images inserted in the body text: Configuration > Content authoring > Text formats and editors, enable the “Lazy load images” filter for each text format. It relies on the filter that tracks images uploaded through the editor to know their dimensions.

Wix

Versions Wix Editor and Wix Studio, Squarespace 7.1, November 2026.

Automatic: the platform defers offscreen media itself. The same applies to Squarespace.

Webflow

Versions Webflow Designer, November 2026.

Each Image element has a loading setting, set to “Lazy” by default. Leave it that way everywhere except in the first screen, where it should be “Eager”.

Laravel

Versions Laravel 11 to 13.

The simplest approach is a Blade component that defers by default, with an option for the first screen. In resources/views/components/image.blade.php:

@props(['src', 'alt', 'width', 'height', 'eager' => false])

<img src="{{ $src }}" alt="{{ $alt }}" width="{{ $width }}" height="{{ $height }}"
     @if($eager) fetchpriority="high" @else loading="lazy" decoding="async" @endif
     {{ $attributes }}>

Usage:

<x-image src="/images/atelier-800.webp" alt="Assembly station in the workshop" width="800" height="533" />

For HTML entered in an editor and stored in the database, add the attribute when saving or rendering:

$html = preg_replace('/<img(?![^>]*\bloading=)/i', '<img loading="lazy"', $html);

This replacement affects every image in the content: if the first one can appear in the first screen, handle it separately.

Symfony

Versions Symfony 6.4, 7.4 and 8.x, Twig 3.

Same principle with a Twig macro or component:

{% macro image(src, alt, width, height, eager = false) %}
    <img src="{{ src }}" alt="{{ alt }}" width="{{ width }}" height="{{ height }}"
         {% if eager %}fetchpriority="high"{% else %}loading="lazy" decoding="async"{% endif %}>
{% endmacro %}

Next.js

Versions Next.js 15 and 16 (App Router and Pages Router).

The next/image component defers by default: there is nothing to add, you just need to avoid disabling it anywhere other than in the first screen. For a first-screen image, write loading="eager", or preload for the LCP image; the priority prop has been deprecated since Next.js 16 but remains the only preload option on Next.js 15. For an iframe, write loading="lazy". For a heavy component located low on the page, next/dynamic postpones the download of its code.

Nuxt

Versions Nuxt 4 (and Nuxt 3, end of life since July 2026), @nuxt/image module 1 and 2.

NuxtImg does not defer by default: add the attribute.

<NuxtImg src="/images/atelier.jpg" width="800" height="533" format="webp"
         alt="Assembly station in the workshop" loading="lazy" />

For a component located below the first screen, the Lazy prefix postpones the download of its code, and since Nuxt 3.16 the hydrate-on-visible prop delays its hydration until it is visible:

<LazyCommentList hydrate-on-visible />

Astro

Versions Astro 5 to 7.

The Image component outputs loading="lazy" and decoding="async" by default. For a framework component located low on the page, the client:visible directive only loads its JavaScript as it approaches the visible area:

<CommentList client:visible />

Common mistakes

  • Deferring the main image or the logo: the LCP slips. This is the most common mistake, often caused by a global plugin setting.
  • Deferring without dimensions: each image that arrives pushes the content down, and CLS (Cumulative Layout Shift) climbs.
  • A library based on the scroll event: images missing from Googlebot's render.
  • data-src attributes with no fallback: without JavaScript, or if the script fails, no image is displayed.
  • Combining native lazy loading and script-based lazy loading on the same images: unpredictable behavior and flickering images.
  • Deferring text: loading the main content or reviews on scroll makes them invisible to crawlers. See make content accessible without user interaction (opens in a new tab).
  • Forgetting iframes: a map or a video embedded at the bottom of the page often weighs more than all the images put together.
  • Replacing images with heavy previews encoded in the HTML: the document grows and the gain disappears.

Frequently asked questions

Is lazy loading bad for SEO?

No, if it is native or based on IntersectionObserver. Googlebot does not scroll the page, but it renders it in a very tall viewport that triggers the loading="lazy" attribute. The risk comes from scripts that wait for a scroll event or an interaction: what they load remains invisible to indexing. It also comes from lazy loading applied to the main image, which delays the LCP.

Should I put loading="lazy" on every image?

No. Defer everything below the first screen, and nothing in it. The main image, the logo and the visuals visible at load time must stay without lazy loading, otherwise the browser requests them late and the LCP slips. Also give width and height attributes to every deferred image, to avoid a layout shift when it arrives.

Do I still need a JavaScript lazy loading library?

In the vast majority of cases, no: the HTML loading="lazy" attribute is enough for images and iframes, with no script. A library remains useful for what native lazy loading does not cover, such as CSS background images or replacing video iframes with a preview image. In that case, check that it relies on IntersectionObserver, and do not combine both mechanisms on the same images.

Does WordPress apply lazy loading automatically?

Yes. WordPress has added loading="lazy" to images that have dimensions since version 5.5, and to iframes since 5.7, sparing the first images in the content. Images hard-coded in the theme and those without dimensions escape it. If an optimization plugin adds its own lazy loading, check that it excludes the main image and do not stack two of them.

Updated on

Topic checklist (PDF)

And now?

In the “Performance and Core Web Vitals” topic

  1. Analyze PageSpeed Insights and Lighthouse
  2. Analyze real-user CrUX data
  3. Target LCP ≤ 2.5 s at the 75th percentile
  4. Target INP ≤ 200 ms at the 75th percentile
  5. Target CLS ≤ 0.1 at the 75th percentile
  6. Target TTFB ≤ 800 ms as a benchmark
  7. Optimize hosting and CDN
  8. Enable Brotli/Gzip
  9. Configure browser and server caching
  10. Minify CSS and JavaScript
  11. Remove unused CSS/JS
  12. Reduce render-blocking resources
  13. Defer non-essential scripts
  14. Limit third-party scripts
  15. Optimize database queries
  16. Optimize fonts (WOFF2, font-display)
  17. Preload only critical resources
  18. Optimize the LCP image without lazy loading
  19. Lazy-load offscreen content
  20. Reserve space for media and ads
  21. Reduce DOM complexity
  22. Test before and after cookie consent
  23. Test on a slow mobile connection
  24. Set a performance budget
  25. Preload likely navigations with Speculation Rules
  26. Make pages eligible for the back/forward cache (bfcache)
  27. Diagnose INP with Long Animation Frames (LoAF)