Last active
May 8, 2021 13:20
-
-
Save ymatuhin/a9601bd608b8de4e4dcc to your computer and use it in GitHub Desktop.
Check WebP Support in browser
This file contains hidden or 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
function checkSupport(fn) { | |
var html = document.documentElement, | |
WebP = new Image(); | |
WebP.onload = WebP.onerror = function() { | |
isSupported = (WebP.height === 2); | |
if (isSupported) { | |
if (html.className.indexOf('no-webp') >= 0) | |
html.className = html.className.replace(/\bno-webp\b/, 'webp'); | |
else html.className += ' webp'; | |
} | |
fn(isSupported); | |
}; | |
WebP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment