Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using modernizer to detect webp support in browser

not sure where I'm going wrong here, but it seems straight forward. I'm trying to detect webp support.

So I have gone to the modernizer site and checked the webp options then downloaded the script.

I have added the script using wordpress functions file, and confirmed it is loading on front end.

Then after the script loads I use the following code to detect if webp is supported:

/*
*   Check webp support
*/
if (Modernizr.webp) {
    alert('webp supported');
} else {
    alert('webp not supported');
}

Alas, I get no alert message.

There is no error messages in the dev tools console either.

Anyone know whats up.

Cheers

like image 639
Web Dev Guy Avatar asked Oct 12 '25 19:10

Web Dev Guy


1 Answers

Modernizr.on('webp', function (result) {
  if (result) {
    // Has WebP support
  }
  else {
    // No WebP support
  }
});
like image 98
Vaibhav N Naik Avatar answered Oct 14 '25 09:10

Vaibhav N Naik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!