Hi,
Sure but the issue is not the html cache in the edge it’s the delivery of static images. The extension never change only the type (JPEG or WEBP).
But sure this could be done with the worker. But here is what you by default will be facing with webp delivery webp based on browser support and only chanign type not extension on the origin if using Cloudflare.
https://www.ads-software.com/plugins/webp-express/#i%20am%20on%20cloudflare
Without configuration, Cloudflare will not maintain separate caches for jpegs and webp; all browsers will get jpeg. To make Cloudflare cache not only by URL, but also by header, you need to use the Custom Cache Key page rule, and add Header content to make separate caches depending on the Accept request header.
However, the Custom Cache Key rule currently requires an Enterprise account. And if you already have that, you may as well go with the Polish feature, which starts at the “Pro” level plan. With the Polish feature, you will not need WebP Express.
To make WebP Express work on a free Cloudflare account, you have the following choices:
You can configure the CDN not to cache jpeg images by adding the following page rule: If rule matches: example.com/*.jpg, set: Cache level to: Bypass
You can set up another CDN (on another provider), which you just use for handling the images. You need to configure that CDN to forward the Accept header. You also need to install a WordPress plugin that points images to that CDN.
You can switch operation mode to “CDN friendly” and use HTML altering.