Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created March 12, 2010 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheeaun/330029 to your computer and use it in GitHub Desktop.
Save cheeaun/330029 to your computer and use it in GitHub Desktop.
Lazy load images or delay them. Put this in the middle or end of <body> for 99.9% efficiency.
(function(){
var imgs = document.getElementsByTagName('img');
var l = imgs.length;
if (l<=0) return;
var srcs = [];
for (var i=0; i<l; i++){
var img = imgs[i];
srcs.push(img.src);
imgs[i].removeAttribute('src');
}
setTimeout(function(){
for (var i=0; i<l; i++){
imgs[i].src = srcs[i];
}
}, 5000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment