Skip to content

Instantly share code, notes, and snippets.

@JacobLett
Forked from bjmiller121/iframe_defer.js
Created March 8, 2016 03:37
Show Gist options
  • Save JacobLett/3cdbbf91dc6603c067f4 to your computer and use it in GitHub Desktop.
Save JacobLett/3cdbbf91dc6603c067f4 to your computer and use it in GitHub Desktop.
Defer loading of iframes
/**
* Defer iframe loading.
*
* Markup:
* <div class="defer-iframe" data-src="{SOURCE URL}" data-{ATTR}="{VAL}"></div>
*/
$(window).load( function(){
if ($('.defer-iframe').length) {
$('.defer-iframe').each( function() {
var $iframe = $('<iframe frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
$iframe.attr($(this).data());
$(this).append($iframe);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment