I work with a large number of images that are stored on a remote server and I'd like to check (with jQuery or JS) which of them are available without loading them entirely. So far I tried 3 solutions, but none of them works like I want:
1.
var http = new XMLHttpRequest();
http.open('HEAD', imageUrl, false);
http.send();
if(http.status >= 400) {
console.log("Error loading " + imageUrl);
}
With this one I get No 'Access-Control-Allow-Origin' header is present on the requested resource....
2.
$.ajax({
type: "HEAD",
async: true,
url: imageUrl
}).done(function() {
}).fail(function() {
console.log("Error loading " + imageUrl);
});
With this one I get the same error as above.
3.
var img = new Image();
img.onerror = function() { console.log("Error loading " + imageUrl) };
img.src = imageUrl;
This one works, but it loads entire images, which makes it very slow.