How to defer Youtube or Vimeo videos in your webpage

First change is that “src” empty like below.
src=””

Second add src URL in “data-src” like bwlow.
data-src=”//www.youtube.com/embed/00000000″

Finally put below jQuery code in your page.

jQuery(window).load(function(){
var vidDefer = document.getElementsByTagName(‘iframe’);
for (var i=0; i<vidDefer.length; i++) {
if(vidDefer[i].getAttribute(‘data-src’)) {
vidDefer[i].setAttribute(‘src’,vidDefer[i].getAttribute(‘data-src’));
}
}
});

Advertisements