您可以像使用任何图像一样使用WebP:
<img src="img.webp" />
然而,由于它并不总是受支持的(请参见http://caniuse.com/#feat=webp),您可以使用以下方法来设置备用方案:
<picture>
<source srcset="img.webp" type="image/webp">
<source srcset="img.jpg" type="image/jpeg">
<img src="img.jpg">
</picture>
<img>
标签里已经有 JPG 格式的图片,你还需要另外一个 <source>
标签吗? - Volpersource
,因为在某些版本的Safari上,它的支持不是很好。 - ElliotCui<img src="img.jpg" onerror="this.src = 'nopicture.gif';"/>