Last active
June 20, 2016 13:08
-
-
Save radist2s/1dcc0c253b126e3c410dde364e87fe59 to your computer and use it in GitHub Desktop.
WEBP Support detector. Adding class to html element.
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 () { | |
function getWebpSupport() { | |
var canvas = document.createElement('canvas'); | |
return canvas && canvas.getContext && canvas.toDataURL('image/webp').indexOf('data:image/webp') == 0 | |
} | |
var webpSupport | |
if (document.cookie.indexOf('webp') == -1) { | |
webpSupport = getWebpSupport() && 1 || 0 | |
document.cookie = 'webp=' + webpSupport + '; path=/' | |
} | |
else { | |
var webpMatch = document.cookie.match(/webp=(\d)/) | |
webpSupport = webpMatch && +webpMatch[1] || 0 | |
} | |
if (webpSupport) { | |
document.documentElement.className += ' webp-supports' | |
} | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment