adamsilverstein / modern-images-wp

Apache License 2.0
81 stars 7 forks source link

Enable <picture> element & convert to multiple formats #1

Open holdit opened 3 years ago

holdit commented 3 years ago

It would be nice if it was possible to convert to multiple formats and then use the <picture> element to make them all available.

This would remove the need to use a polyfill for WebP (it's not only IE, but Safari too - they only added support recently), AVIF, and other formats. Smaller website operators already have difficulties meeting Google PageSpeed requirements (Lighthouse 8.0 is even stricter), so more js files is not what they need.

It would also make it easier for WordPress to adopt newer formats. WebP was released ~10 years ago... will we have to wait another 10 years for AVIF? With <picture> we can have WebP and/or AVIF and a JPG/PNG/GIF fallback.

As for downsides, I can think of 3:

For the disk space, I don't think this is a huge issue as even shared hosting plans come with a lot of space these days.

Regarding upload speeds, processing could happen in the background for some formats. For example, if it's slow to convert to AVIF, WordPress could generate a WebP copy first and then convert AVIF later on. If a AVIF file is uploaded, then conversion could happen in real time. (Plugins like EWWW Image Optimizer support this and it's useful when we're uploading multiple files or are on slow servers.)

CPU usage... well, not sure if there's much that can be done here.

Maybe this shouldn't the default behaviour, but I think it would be useful if WordPress supported this.

adamsilverstein commented 3 years ago

Hi @holdit! Thanks for opening this issue.

I agree with almost everything you say and reached somewhat of the same conclusion about the CPU usage. Unfortunately, CPU resource contention is a huge issue, especially for hosts that have many sites on "shared" resources. So you are probably right that this couldn't be a default for WordPress.

This repo would be a great place to experiment with that feature. Have you seen this nifty web app that helps you build the picture element? https://just-gimme-an-img.vercel.app/

luc122c commented 3 years ago

Regarding the CPU usage, could you delay the creation of optimised versions of images to a time of less traffic? Perhaps hooking into wp-cron?

adamsilverstein commented 3 years ago

Regarding the CPU usage, could you delay the creation of optimised versions of images to a time of less traffic? Perhaps hooking into wp-cron?

@luc122c - Right, WordPress would handle this fine, the issue remains though - overall we would be doubling the number of images generated, increasing load on servers (especially for hosts).