Skip to content

Instantly share code, notes, and snippets.

@jaredreich
Created February 20, 2019 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredreich/0234151583c22dcbe1ea9696b1c53a0d to your computer and use it in GitHub Desktop.
Save jaredreich/0234151583c22dcbe1ea9696b1c53a0d to your computer and use it in GitHub Desktop.
Check WebP support browser-side
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