Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Created September 28, 2010 16:00
Show Gist options
  • Save badsyntax/601260 to your computer and use it in GitHub Desktop.
Save badsyntax/601260 to your computer and use it in GitHub Desktop.
// This is the conclusion to my tests of determining the best way to cache images.
// I used apache access logs to determine when an image was actually requested from the web server.
// The following code, although not that elegant, works fine in IE6, IE7, IE8, FF3, Safari, Chrome, Opera
var _cacheImages = [];
function cacheImages(images){
$.each(images, function(index, val){
var image = new Image()
image.src = val;
_cacheImages.push( image );
});
};
// The following will NOT work in IE6:
function cacheImages(images){
$.each(images, function(index, val){
var image = new Image()
image.src = val;
});
};
// Also the following will NOT work in IE6 (sorry!)
function cacheImages(images){
$.each(images, function(index, val){
new Image().src = val;
});
};
// It seems you need to save a reference to the image object in order for IE6 to send a request to retrieve it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment