Skip to content

Instantly share code, notes, and snippets.

@cole007
Created January 7, 2015 09:31
Show Gist options
  • Save cole007/f4664dbd425779577634 to your computer and use it in GitHub Desktop.
Save cole007/f4664dbd425779577634 to your computer and use it in GitHub Desktop.
Simple lazy load technique
<!-- place this at bottom the of your HTML page. it has to be after your images appear in the DOM -->
<script>
var imgs = document.getElementsByTagName('img');
// var i = 1 skips first instance. use 0 to do all images
for (var i = 1; i < imgs.length; i++) {
var src = imgs[i].src;
imgs[i].setAttribute('data-src',src);
// whatever, placeholder image
imgs[i].src="hello.jpg";
}
</script>
// requires unveil.js
// http://luis-almeida.github.io/unveil/
$("img").unveil(200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment