ildarmustafin,
в примере 5 первых попыток с ошибкой, повтор загрузки через 1 секунду.
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.temp {
height: 32px;
width: 32px;
background-position: 0 -34px;
text-decoration: none;
background-color: transparent;
background-image: var(--img, url(images/css_sprites.png));
margin: 3px;
display: inline-block;
}
</style>
</head>
<body>
<div class="temp"></div>
<div class="temp"></div>
<div class="temp"></div>
<div class="temp"></div>
<div class="temp"></div>
<script>
let k = 5;
const loadSrc = (src, delay) => {
const img = new Image();
img.src = k-- > 0 ? "" : src; //img.src = src;
img.decode()
.then(() => {
document.body.style.setProperty('--img', `url(${src})`);
})
.catch(() => {
console.log(k)
setTimeout(() => loadSrc(src, delay), delay)
})
}
loadSrc('https://javascript.ru/forum/images/smilies/smile.gif', 1000)
</script>
</body>
</html>