defer iframe code example
Example: How To Defer Iframe
// Move src to data-src
<iframe src="" data-src="https://www.youtube.com/embed/JdyDz6quE18"></iframe>
// Add this script
function deferIframe() {
var iframeElem = document.getElementsByTagName('iframe');
for ( var i = 0; i < iframeElem.length; i++ ) {
if(iframeElem[i].getAttribute('data-src')) {
iframeElem[i].setAttribute('src',iframeElem[i].getAttribute('data-src'));
}
}
}
window.onload = deferIframe;