Skip to content

Instantly share code, notes, and snippets.

@Ankhena
Created January 21, 2023 09:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ankhena/1a996c3d3e2ffa6e26744f4925be6fa5 to your computer and use it in GitHub Desktop.
Save Ankhena/1a996c3d3e2ffa6e26744f4925be6fa5 to your computer and use it in GitHub Desktop.
function checkWebP(callback){
let webP = new Image();
webP.onload = webP.onerror = function(){
callback(webP.height == 2);
};
webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
};
checkWebP(function(support){
if(support) document.body.classList.add("webp");
else document.body.classList.add("no-webp");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment