Skip to content

Instantly share code, notes, and snippets.

@netsuite
Created April 8, 2014 20:11
Show Gist options
  • Save netsuite/10183874 to your computer and use it in GitHub Desktop.
Save netsuite/10183874 to your computer and use it in GitHub Desktop.
js: preload images
function preloadImages(srcs) {
if (!preloadImages.cache) {
preloadImages.cache = [];
}
var img;
for (var i = 0; i < srcs.length; i++) {
img = new Image();
img.src = srcs[i];
preloadImages.cache.push(img);
}
}
// then to call it, you would use this
var imageSrcs = [];
setTimeout(function() {
imageSrcs.push("/siteImg/lb-mugs-large.jpg");
preloadImages(imageSrcs);
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment