Skip to content

Instantly share code, notes, and snippets.

@herrkessler
Forked from jakearchibald/1.js
Last active August 17, 2017 07:45
Show Gist options
  • Save herrkessler/60af220ee35325b64e8a9277c3a18d5c to your computer and use it in GitHub Desktop.
Save herrkessler/60af220ee35325b64e8a9277c3a18d5c to your computer and use it in GitHub Desktop.
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