YouTube supports WebP thumbnails (example). It would be great to support these by default, but unfortunately not all videos come with a WebP thumbnail (this doesn't work but this one does).
Possible implementations:
Use the <picture> element to show the WebP thumbnail with the regular .jpg fallback. This is the easiest approach but would also result in 404 errors for any video without a WebP thumbnail.
Use wp_remote_get or something similar to check for WebP existence before rendering it on the page. This would get rid of the 404 error, but also add an extra external request on every page load. Not great.
Hook into save_post and check for WebP existence when saving or updating a post. Results could be saved as post meta, similar to the WordPress oEmbed implementation.
Use wp_remote_get to check for WebP existence and save the result in a transient.
The last option seems to be the best so far, with no 404's or unnecessary requests on page render. Existing embeds could fallback to regular JPEG thumbnails if they haven't been updated since activating the plugin.
508c79943300e700d3f97f52482ba4f6148eea28 adds preliminary support for WebP using transients. I'm leaving this open for now since I need to do some more testing with different videos.
YouTube supports WebP thumbnails (example). It would be great to support these by default, but unfortunately not all videos come with a WebP thumbnail (this doesn't work but this one does).
Possible implementations:
<picture>
element to show the WebP thumbnail with the regular.jpg
fallback. This is the easiest approach but would also result in 404 errors for any video without a WebP thumbnail.wp_remote_get
or something similar to check for WebP existence before rendering it on the page. This would get rid of the 404 error, but also add an extra external request on every page load. Not great.save_post
and check for WebP existence when saving or updating a post. Results could be saved as post meta, similar to the WordPress oEmbed implementation.wp_remote_get
to check for WebP existence and save the result in a transient.The last option seems to be the best so far, with no 404's or unnecessary requests on page render. Existing embeds could fallback to regular JPEG thumbnails if they haven't been updated since activating the plugin.