Created
June 1, 2021 02:40
-
-
Save milksense/e9802fc1895f7e84804dd929c0b8e4bf to your computer and use it in GitHub Desktop.
Is WEBP supported
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let webpSupported = undefined; | |
/* export ES6+ */ async function isWebpSupported() { | |
if (webpSupported !== undefined) { | |
return webpSupported; | |
} | |
const promise = new Promise(resolve => { | |
const image = new Image(); | |
image.onload = function () { | |
resolve(image.width === 2 && image.height === 1); | |
} | |
image.onerror = function () { | |
resolve(false); | |
} | |
image.src = 'data:image/webp;base64,UklGRjIAAABXRUJQVlA4ICYAAACyAgCdASoCAAEALmk0mk0iIiIiIgBoSygABc6zbAAA/v56QAAAAA=='; | |
}); | |
return webpSupported = await promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment