Skip to content

Instantly share code, notes, and snippets.

@bradleykronson
Created August 19, 2013 13:57
Show Gist options
  • Save bradleykronson/6269433 to your computer and use it in GitHub Desktop.
Save bradleykronson/6269433 to your computer and use it in GitHub Desktop.
Preloading Images
(function($) {
var cache = [];
// Arguments are image paths relative to the current page.
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}
}
jQuery.preLoadImages("image1.gif", "/path/to/image2.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment