DEV Community

Discussion on: How to embed YouTube and Vimeo the light way

Collapse
 
robole profile image
Rob OLeary • Edited

I was going to look into this soon as well! I saw this article on lazy loading youtube vidoeos recently, How to lazy load YouTube videos with vanilla JavaScript , and wanted to investigate it.

One thing that people forget or dont know is that you can lazy load an iframewith loading=lazy (Firefox is a laggard in support however and Safari has it behind a flag). This will spare you the upfront cost of loading the video scripts and give a faster page load if you do have to go the iframe route.

Collapse
 
madsstoumann profile image
Mads Stoumann

Yes, good point! It's only Chrome for now, but Safari has lazy-load for iframes behind a flag in v16. Firefox status is unknown.

Collapse
 
robole profile image
Rob OLeary • Edited

Yep. Let's hope Firefox follows suit soon.

Considering so many embedded videos are sourced from youtube, it is an important one IMO. I just try to avoid YouTube altogether.

I wrote about lazy-loading videos a while back, you can use preload="none" and the video file is only downloaded when the user hits play.