5 ways to lessen the affect YouTube videos have on site performance scores

Embedded YouTube videos can slow down your page and hurt your Lighthouse performance score, especially in the Largest Contentful Paint (LCP) and Total Blocking Time (TBT) metrics. Here are some ways to improve it:

1. Lazy Load the YouTube Video (Best Option)

Instead of embedding the YouTube iframe directly, replace it with a clickable thumbnail that loads the video only when clicked.

  • Use a static image (YouTube thumbnail) as a placeholder.
  • When the user clicks, replace the image with the actual iframe.
  • This avoids loading the heavy YouTube player on initial page load.

Example code:

<div class="youtube-wrapper" data-id="VIDEO_ID">
    <img src="https://img.youtube.com/vi/VIDEO_ID/hqdefault.jpg" alt="YouTube Thumbnail">
    <button class="play-button">▶</button>
</div>

<script>
document.querySelectorAll('.youtube-wrapper').forEach(wrapper => {
    wrapper.addEventListener('click', function () {
        const videoId = this.getAttribute('data-id');
        const iframe = document.createElement('iframe');
        iframe.setAttribute('src', `https://www.youtube.com/embed/${videoId}?autoplay=1&rel=0`);
        iframe.setAttribute('frameborder', '0');
        iframe.setAttribute('allow', 'autoplay; encrypted-media');
        iframe.setAttribute('allowfullscreen', 'true');
        this.innerHTML = ''; // Remove thumbnail
        this.appendChild(iframe);
    });
});
</script>

2. Use YouTube’s Lite Embed

Google provides a lite YouTube embed solution that is much lighter than the default iframe:

  1. Use lite-youtube.
  2. Replace your <iframe> with <lite-youtube>.

Example:

<lite-youtube videoid="VIDEO_ID"></lite-youtube>
<script type="module">
    import 'https://cdn.jsdelivr.net/npm/lite-youtube-embed/src/lite-yt-embed.js';
</script>

Instead of embedding a full YouTube player, use an image and load the video on click.

<iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID" loading="lazy"></iframe>

This reduces third-party cookies and improves privacy while still helping performance.


4. Preload & Optimize Image Thumbnails

If you use a placeholder image, preload it to speed up rendering:

<link rel="preload" href="https://img.youtube.com/vi/VIDEO_ID/hqdefault.jpg" as="image">

5. Reduce Render-Blocking Scripts

  • If you must use the iframe, defer loading it using loading="lazy":
<iframe src="https://www.youtube.com/embed/VIDEO_ID" loading="lazy"></iframe>

The best approach is to use a thumbnail with lazy loading, either manually or with lite-youtube-embed. This can significantly improve your Lighthouse scores, especially LCP and TBT.

More Articles
  • The Complete Accessibility Checklist for WordPress Content Editors

    Maintaining a fully accessible WordPress website is not just a technical responsibility—it’s an ongoing content discipline. If you manage or publish posts, your decisions directly impact whether people using screen readers, keyboard navigation, or other assistive technologies can fully engage with your content. This guide is designed as a practical, repeatable reference for anyone creating…

  • Detailed close-up of a strong shiny metallic chain link against a blurred background, emphasizing security.

    Best practices for adding links to web copy to maximize SEO benefits

    There isn’t a strict rule for the exact number of hyperlinks in body copy, but there are widely accepted best practices based on usability, SEO, and readability. The goal is to include links where they add value, not simply to increase quantity. 🔗 1. General guideline (most common rule of thumb) For standard website pages…

  • website, web design, development, code, programming, marketing, office, business, agency, website, website, web design, web design, web design, web design, web design, agency

    25 Free Website Testing Resources Every Web Developer Should Know

    Modern web development extends far beyond writing functional code. Developers must ensure their websites are secure, accessible, fast, and compliant with modern search and usability standards. Fortunately, there are many powerful free tools available that help identify issues, validate markup, test accessibility, analyze performance, and improve overall site quality. Below is a curated list of…

Skip to content