Skip to content

Instantly share code, notes, and snippets.

@jonlow
Created July 4, 2014 06:00
Show Gist options
  • Save jonlow/021aee0876f9f76bf51d to your computer and use it in GitHub Desktop.
Save jonlow/021aee0876f9f76bf51d to your computer and use it in GitHub Desktop.
Preload an array of images into browser cache
function preloadImages(array) {
if (!preloadedImages.list) {
preloadedImages.list = [];
}
for (var i = 0; i < array.length; i++) {
var img = new Image();
img.src = array[i];
preloadedImages.list.push(img);
}
}
var imageURLs = [
"url1.jpg",
"url2.jpg",
"url3.jpg"
];
preloadImages(imageURLs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment