Created
July 4, 2014 06:00
-
-
Save jonlow/021aee0876f9f76bf51d to your computer and use it in GitHub Desktop.
Preload an array of images into browser cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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