Created
February 20, 2019 15:02
-
-
Save jaredreich/0234151583c22dcbe1ea9696b1c53a0d to your computer and use it in GitHub Desktop.
Check WebP support browser-side
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
const supportsWebP = () => new Promise(resolve => { | |
const webP = new Image(); | |
webP.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA='; // 1x1 black pixel | |
webP.onload = webP.onerror = () => resolve(webP.height === 1); | |
}) | |
supportsWebP().then(hasWebP => console.log(hasWebP)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment