Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Last active February 25, 2024 04:22
Show Gist options
  • Save jakearchibald/6c43d5c454bc8f48f83d8471f45698fa to your computer and use it in GitHub Desktop.
Save jakearchibald/6c43d5c454bc8f48f83d8471f45698fa to your computer and use it in GitHub Desktop.
async function supportsWebp() {
if (!self.createImageBitmap) return false;
const webpData = 'data:image/webp;base64,UklGRhIAAABXRUJQVlA4TAYAAAAvQWxvAGs=';
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()) {
// …
}
else {
// …
}
}());
});
@patrickkettner
Copy link

shave a few off your data uri with data:image/webp;base64,UklGRhIAAABXRUJQVlA4TAYAAAAvQWxvAGs= (pulled from mathias' small)

@shabbir-dhangot
Copy link

Not working in iphone 6s. Issue causing due to async function. Similar issue on SO.
https://stackoverflow.com/questions/53358706/angular-web-app-async-functions-observables-not-working-properly-in-ios-devi

@kane-mason
Copy link

iOS14 introduces webp support, anyone know if this will detect there correctly?

@jakearchibald
Copy link
Author

It should do

@kane-mason
Copy link

Mmm iOS 14 beta 2 has no support for createImageBitmap, yet?

@kane-mason
Copy link

Actually not seeing any webp support of any kind yet, guess its still coming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment