SVITY
10/3/2016 - 8:02 PM

How to detect image is cached or not?

How to detect image is cached or not?

//Using .complete and .height + .width gives the expected results (FF 3.6.23, Chromium 14).
function isCached(src) {
    var image = new Image();
    image.src = src;
    return image.complete || image.width + image.height > 0;
}

var url = 'http://design.ubuntu.com/wp-content/uploads/ubuntu-logo32.png';

isCached(url); //false
isCached(url); //true