I’ve seen several sites containing scripts to handle lazy loading of images (meaning, it displays images only when the user scrolls to their location further down the page).
Is there any such script for lazy loading YouTube videos that are displayed in iframes?
At the very least, what is involved in detecting where the user is scrolled to?
Thank you for the idea. Unfortunately, my pages are not using Jquery (not needed on ay of the pages) and I hesitate to include it in this mobile version.
Sitepoint recently had an article on Yourtube videos and using JavaScript and Json to eliminate iFrames and download an image along with relevant information. I am in the process of fine tuning this process for my needs and the latest version can be seen here:
You include the script in your page and initialize with: LazyYT.init(".js-lazyYT");
You might run into a couple of issues with older browsers, but at least this should let you test things.
If you did use it, we could always make the code more robust.
So what this script does is load only a preview of the video so it loads faster? The iFrame version doesn’t do that already? Thanks for any clarification!
When I use an iFrame, then clicking on the still image plays the video in every case.
This is almost true with LazyYT: In one case, the image would not play, saying that it must be played on YouTube. It was disabled for playback on other websites by the video owner. Yet it played fine in the embedded iFrame code.
The script loads a preview image, then waits until the video is actually clicked to load and start the full Youtube video.
If you embed an iframe then when a user hits your page, then they will download whatever is contained in the iframe.
Oh ok. That sounds a bit strange, but I would need to take a closer look.