videojs / videojs-youtube

YouTube playback technology for Video.js
1.13k stars 547 forks source link

iframe lazyloading #405

Open Geschan opened 8 years ago

Geschan commented 8 years ago

Hi,

I have added multiple videos on one site and having some performance issues especially with Firefox. The browser struggles in loading all the iframes at the same time.

It would be helpfull if there is an option to lazyload the iframes only if the play icon is clicked. The loading of the video would take a little longer but the performance would be much better I think.

Best Gesh

emkayy commented 7 years ago

This would actually be very easy to achieve! Just remove line 731 loadScript('https://www.youtube.com/iframe_api', apiLoaded); And add this block inside the else statement of the constructor in line 59

this.one(this.el_.parentNode, 'click', function (argument) {
    loadScript('https://www.youtube.com/iframe_api', apiLoaded);
});

You could also wrap line 731 in if (this.options_.autoplay) and line 59 in if (!this.options_.autoplay) to make it compatible with autoplay.

emkayy commented 7 years ago

For performance reasons, it would be very nice if you cound make this an config option! ... Since it is so little effort to achieve!

Thanks!