这是我的解决方案-大约需要6毫秒,而且我认为WebP只是现代浏览器的一项功能。使用canvas.toDataUrl()函数而不是图像使用另一种方法来检测特征:
function canUseWebP() { var elem = document.createElement('canvas'); if (!!(elem.getContext && elem.getContext('2d'))) { // was able or not to get WebP representation return elem.toDataURL('image/webp').indexOf('data:image/webp') == 0; } // very old browser like IE 8, canvas not supported return false;}


