Created
June 12, 2017 21:25
-
-
Save RohitRox/e5d2b7de1a2cb7149e7c238243076b39 to your computer and use it in GitHub Desktop.
Minimal webp support check addition to Modernizr
This file contains 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 (document) { | |
'use strict'; | |
var webpImg = new Image(); | |
webpImg.onerror = function() { | |
setModernizr(false); | |
} | |
webpImg.onload = function(){ | |
var root = document.getElementsByTagName('html')[0]; | |
if (root.classList) { | |
root.classList.add('webp'); | |
} else { | |
root.className += ' webp'; | |
} | |
setModernizr(true); | |
}; | |
webpImg.src = 'data:image/webp;base64,UklGRjIAAABXRUJQVlA4ICYAAACyAgCdASoBAAEALmk0mk0iIiIiIgBoSygABc6zbAAA/v56QAAAAA=='; | |
function setModernizr(support) { | |
Modernizr.addTest('webp', function(){ | |
return support; | |
}); | |
} | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment