Skip to content

Instantly share code, notes, and snippets.

@martinluz
Created January 14, 2013 13:13
Show Gist options
  • Save martinluz/4529970 to your computer and use it in GitHub Desktop.
Save martinluz/4529970 to your computer and use it in GitHub Desktop.
Javascript image preloader
//Source: http://stackoverflow.com/a/476681
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img/>')[0].src = this;
// Alternatively you could use:
// (new Image()).src = this;
});
}
// Usage:
preload([
'img/imageName.jpg',
'img/anotherOne.jpg',
'img/blahblahblah.jpg'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment