WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
347 stars 94 forks source link

Improve image handling approach in Modern Image Formats #1259

Open adamsilverstein opened 3 months ago

adamsilverstein commented 3 months ago

Feature Description

Switch from using the_content filter to using wp_calculate_image_srcset when replacing images.

As @joemcgill points out in https://github.com/WordPress/performance/pull/1236#pullrequestreview-2069741635 we should probably switch the image processing approach. Currently the webp_uploads_update_image_references function is attached to the_content filter and processes all images on the page using a regex. Instead, we can leverage the filters core runs on images after it does a similar regex against the content. Namely, the wp_calculate_image_srcset or wp_content_img_tag filters are potential places to add our logic.

westonruter commented 3 months ago

And note that webp_uploads_wrap_image_in_picture() is necessarily using the wp_content_img_tag filter.