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
  • A tranquil scene of Canadian Geese flying in formation against a clear sky in Decatur, Alabama.

    How to Migrate a Magento Commerce Website to WordPress and WooCommerce: A Step-by-Step Guide

    If your Magento Commerce website has become expensive to maintain, difficult to customize, or more complex than your business needs, you’re not alone. Many businesses are making the move to WordPress and WooCommerce to reduce costs, simplify website management, and gain greater flexibility for content marketing and SEO. A successful migration requires more than simply…

  • Close-up of a bright yellow disabled symbol on textured asphalt, indicating accessibility.

    Website Accessibility Review Workflow

    Version: 1.0Standard: WCAG 2.2 AAAudience: Web Developers, QA Testers, UI Designers Phase 1 – Automated Accessibility Scan Goal: Find common accessibility issues before manual testing. Checklist ☐ Run an accessibility scan on every page template. ☐ Review all reported errors. ☐ Fix high-impact issues first: ☐ Re-run scan until no critical issues remain. Recommended Tools…

  • accessible parking spot comparing ADA rules to WCAG rules

    What Is the Industry Standard Website Scanner for WCAG Compliance?

    If you’re trying to make your website accessible, one of the first questions you’ll probably ask is: “What’s the industry-standard scanner for WCAG compliance?” The short answer is: there isn’t just one. While several excellent accessibility scanners exist, no automated tool can certify that a website is fully compliant with the Web Content Accessibility Guidelines…