<script>
fetch('/img/pixel-webp.webp')
.then(res => {
if (res.ok) {
document.documentElement.classList.add('webp');
} else {
document.documentElement.classList.add('no-webp');
}
})
.catch(err => {
document.documentElement.classList.add('no-webp');
});
</script>
src
в new Image()
и у него ловить load
или error
var webPsupport = (function() {
var webP = new Image();
webP.onload = WebP.onerror = function () {
callback(webP.height == 2);
};
webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
});
document.write(webPsupport ? 'webP supported!' : 'webP not supported.');