Skip to content

Instantly share code, notes, and snippets.

@bjankord
Created November 6, 2012 22:09
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 bjankord/4027941 to your computer and use it in GitHub Desktop.
Save bjankord/4027941 to your computer and use it in GitHub Desktop.
Test for WebP Support
var img = new Image(),
supported = false;
img.src ="data:image/webp;base64,UklGRkYAAABXRUJQVlA4IDoAAABwAgCdASoEAAQAAYcIhYWIhYSIiQIADAzdrBLeABAAAAEAAAEAAPKn5Nn/0v8//Zxn/6H3QAAAAAA=";
img.onload = function() { supported = true; }
img.onerror = function(e) {}
window.onload = function() {
if (supported) {
document.getElementsByTagName('html')[0].className += ' webp';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment