IE9 is showing false complete
property with the following:
$("<img/>",{src:"http://farm2.static.flickr.com/1104/1434841504_edc671e65c.jpg"}).each(function(){console.log(this.complete);});
If you run this code in a browser console, (allow enough time for the image to load) then run it again. IE9 is the only browser I've tested showing false the second time. This seems to be a known bug, from some simple google searching. I need a workaround if anyone has one.
This could be a timing issue, as letting the code above set a global variable a la:
var img = $("<img....
and then testing that variable's properties gives different results:
img[0].complete === true
and
img[0].readyState === "complete"
There must be some other way of getting this infomation. Any ideas... Thanks!
I use this:
A sample:
This is how i usually preload an image:
I haven't deeply debugged it in IE9, but I haven't ran into any issues with it.
the code was pulled from https://github.com/tentonaxe/jQuery-preloadImages/blob/master/jquery.preloadimages.js and modified.
I know this was asked a million years ago, but I figure I would contribute my solution which is similar but has less overhead and i/o.
Basically, you create a custom jQuery method that performs the similar feats all in one function:
This consolidates the checking of all possible events into one (both cached and uncached), but also makes the method chainable. You can call it with:
Works cross-browser, back to IE6. Notice it checks for caching first, and if not triggers a namespaced load event only once to prevent reloads in case you call the function with that logic twice, but also to allow custom load events to be bound (if applicable).
You can't tell if it's cached, but you can force a fresh load by "salting" the filename:
You could try an AJAX request on the image and see the status code. If it's 304 it means the image was cached. Not sure how well that would work though. Maybe AJAX does some cache-busting.