keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

update WebP URL conversion #116

Closed coreykn closed 4 years ago

coreykn commented 4 years ago

Remove both Cache_Enabler_Disk::_convert_webp_src() and Cache_Enabler_Disk::_convert_webp_srcset() and instead update Cache_Enabler_Disk::_convert_webp() to handle converting the image path(s) to WebP. This simplifies the logic and still allows one (e.g. src) or more (e.g. srcset) image URLs to be replaced. Explode by ',' instead of ', ' and then trim spaces to avoid edge cases (#115). When imploding the proper formatting will be applied. This change allows images in any directory to be replaced instead of images only in the uploads directory (default wp-content/uploads or custom). The .webp extension is now first appended and then the default extension is removed because it makes the conversion more simple by requiring less logic.

Update WebP regular expression matching:

When reviewing all hooks for version 1.5.0 we may want to create new filter hooks for the changes above, for example:

Regex tests (until unit tests are written):

Closes #48 Fixes #51 and fixes #115