← Back to context

Comment by jsheard

7 months ago

Fun fact: Googles own web performance team recommends avoiding YouTube embeds because they're so obscenely bloated. Placing their <iframe> on a page will pull in about 4MB of assets, most of which is Javascript, even if the user never plays the video.

https://developer.chrome.com/docs/lighthouse/performance/thi...

YouTubes frontend people just don't care about bloat, even when other Googlers are yelling at them to cut it out.

We lazy-load Youtube iframes, fixes the problem pretty easily.

  • Depends on how you do it, loading="lazy" helps a bit, but the iframe still gets loaded when it enters the viewport even if the user has no intention of watching the video. The best approach is to initially show a fake facade of the player and only swap in the real iframe after the user interacts with it, which is what Google recommends doing in that article.

    • >but the iframe still gets loaded when it enters the viewport even if the user has no intention of watching the video

      That doesn't affect page speed scores if the video is "below the fold", and that's all that I really care about. If Google Lighthouse doesn't complain about it, then my job is done.