Implement lazy loading for videos

Videos make your content richer, but they’re also heavy. Standard embeds load immediately upon page visit – which slows load time and negatively affects your Core Web Vitals. The solution: lazy loading. In this article, I’ll show you how to load videos only as soon as they come into view, without external plug-ins or performance issues.

1. Why lazy loading for video?

A standard YouTube or Vimeo embed automatically loads multiple external scripts, thumbnails and iframe resources upon page visit.

Disadvantages:

  • Slow LCP (Largest Contentful Paint).
  • Lower PageSpeed score
  • Poorer mobile performance
  • Unnecessary data consumption with videos at the bottom of the page

Lazy loading causes the video to load only when the visitor scrolls to it.

2. Operation: from image to iframe on scroll

The lazy load technique works as follows:

  1. You display a static thumbnail (e.g., JPG or WebP)
  2. When scrolling (via the Intersection Observer API) replace this thumbnail with the actual <iframe>
  3. Result: faster loading, no render-blocking scripts, better user experience

3. HTML + JavaScript example (YouTube)

HTML:

html
<div class="video-wrapper" data-video-id="dQw4w9WgXcQ">
  <img src="https://img.youtube.com/vi/dQw4w9WgXcQ/hqdefault.jpg" alt="Video preview" loading="lazy">
  <button class="play-button" aria-label="Video afspelen">▶</button>
</div>
Copy to Clipboard

CSS (optional):

css
.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  cursor: pointer;
}
.video-wrapper img {
  width: 100%;
  display: block;
}
.play-button {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  background: none;
  border: none;
  color: white;
}
Copy to Clipboard

JavaScript (Intersection Observer):

html
 <script>
 document.addEventListener('DOMContentLoaded', function () {
  const videos = document.querySelectorAll('.video-wrapper');
  const loadIframe = (el) => {
    const videoId = el.getAttribute('data-video-id');
    const iframe = document.createElement('iframe');
    iframe.setAttribute('src', 'https://www.youtube.com/embed/' + videoId + '?autoplay=1');
    iframe.setAttribute('frameborder', '0');
    iframe.setAttribute('allow', 'autoplay; encrypted-media');
    iframe.setAttribute('allowfullscreen', '');
    iframe.style.width = '100%';
    iframe.style.height = '100%';
    el.innerHTML = '';
    el.appendChild(iframe);
  };
  const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        loadIframe(entry.target);
        observer.unobserve(entry.target);
      }
    });
  });
  videos.forEach(video => {
    observer.observe(video);
  });
});
</script>
Copy to Clipboard

Aan de slag met SEO? Neem gerust contact op.

Senior SEO-specialist






    4. Alternative: lazy loading with plugins (with CMS)

    For WordPress sites:

    • WP Rocket – Lazy load for images and videos
    • Lazy Load for Videos – Specific plugin for video
    • LiteSpeed Cache – All-in-one optimization, including video lazy loading

    Note: visually check that embedded videos still load correctly after installation.

    5. Additional optimization: compress thumbnails

    Most video thumbnails are 480px or larger. Optimize them with:

    • WebP format (smaller, same quality)
    • Compression via Squoosh
    • loading=”lazy” at <img>

    Also, use an alt text for context + SEO.

    In conclusion

    Lazy loading for videos is a no-brainer: better load time, better UX, and better scores in Lighthouse/PageSpeed. Through a simple combination of HTML, CSS and JS, you load videos only when needed – and avoid unnecessary delays in initial visits.

    Senior SEO-specialist

    Ralf van Veen

    Senior SEO-specialist
    Five stars
    My clients give me a 5.0 on Google out of 85 reviews

    I have been working for 12 years as an independent SEO specialist for companies (in the Netherlands and abroad) that want to rank higher in Google in a sustainable manner. During this period I have consulted A-brands, set up large-scale international SEO campaigns and coached global development teams in the field of search engine optimization.

    With this broad experience within SEO, I have developed the SEO course and helped hundreds of companies with improved findability in Google in a sustainable and transparent way. For this you can consult my portfolio, references and collaborations.

    This article was originally published on 4 June 2025. The last update of this article was on 18 July 2025. The content of this page was written and approved by Ralf van Veen. Learn more about the creation of my articles in my editorial guidelines.