Skip to content

Instantly share code, notes, and snippets.

@jecfish
Created May 20, 2020 11:38
Show Gist options
  • Save jecfish/3b0874bdb559768f3dd6c7b34abddc65 to your computer and use it in GitHub Desktop.
Save jecfish/3b0874bdb559768f3dd6c7b34abddc65 to your computer and use it in GitHub Desktop.
Test WebP Support
/* test webp support, add .webp class to body */
{
canvas = typeof document === 'object' ?
document.createElement('canvas') : {};
canvas.width = canvas.height = 1;
if (canvas.toDataURL && canvas.toDataURL('image/webp').indexOf('image/webp') === 5) {
document.querySelector('body').classList.add('webp')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment