-
-
Save herrkessler/60af220ee35325b64e8a9277c3a18d5c to your computer and use it in GitHub Desktop.
check webp support by jakearchibald -- https://gist.github.com/jakearchibald/6c43d5c454bc8f48f83d8471f45698fa
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
async function supportsWebp() { | |
if (!self.createImageBitmap) return false; | |
const webpData = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA='; | |
const blob = await fetch(webpData).then(r => r.blob()); | |
return createImageBitmap(blob).then(() => true, () => false); | |
} | |
addEventListener('install', event => { | |
event.waitUntil(async function() { | |
if (await supportsWebp()) { | |
document.body.classList.add('webp'); | |
} | |
else { | |
document.body.classList.add('no-web'); | |
} | |
}()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment