Skip to content

Instantly share code, notes, and snippets.

@RohitRox
Created June 12, 2017 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitRox/e5d2b7de1a2cb7149e7c238243076b39 to your computer and use it in GitHub Desktop.
Save RohitRox/e5d2b7de1a2cb7149e7c238243076b39 to your computer and use it in GitHub Desktop.
Minimal webp support check addition to Modernizr
(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