JSFiddle - React, Tailwind, and code Playground
JavaScript
var imgs = [
'https://i.imgur.com/jUF6rcP.png',
'https://i.imgur.com/4DJnFif.png',
//'https://i.imgur.com/2MUX2qJ.jpg', // uncomment for early exit
'https://i.imgur.com/yd6mjSY.png'
];
function reqListener () {
var type = this.getResponseHeader('Content-Type');
console.log('Checking:', type);
if (type === 'image/png') {
var isComplete = nextImg();
if (isComplete) {
console.log('ALL COMPLETE');
}
} else {
console.log('EARLY EXIT');
}
}
function nextImg () {
var img = imgs.shift();
if (img) {
oReq.open("HEAD", img);
oReq.send();
return false;
}
return true;
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
nextImg();