Can Cloudflare Image Resizing add and serve the srcset?

We’re running Cloudflare with a Pro account on a Wordpress site with all Cloudflare > speed settings activated including Image Resizing.

Can Cloudflare (possibly by Workers) see tags in our html and rewrite them into the srcset version with those assets served from Cloudflare’s CDN? For instance from…

<img src="myimage.jpg" alt="this is an image">

to

<img srcset="myimage.jpg 480w, myimage.jpg 800w" sizes="(max-width: 600px) 480px,
         800px"  src="myimage.jpg" alt="this is an image" />

This would be a big speed boost to our site.

Usually Wordpress does intercept tags and rewrite them with srcset. But we’re serving raw html from a custom post type that does not go through Wordpress’ usual the_content filter.

We’re wondering if Cloudflare, maybe through Workers, can accomplish this.

Just turning on Cloudflare Image Resizing didn’t change the html we see on cached pages. It’s still like

<img src="myimage.jpg" alt="this is an image">

Hi, in order to use Image Resizing product, you need to define resizing variants, example:

Unfortunately, Image Resizing does not interact with html page, and hence there’s no rewriting, but you can use html rewriter HTMLRewriter · Cloudflare Workers docs.

You should be aware though the page itself won’t be cached when using worker.

This topic was automatically closed after 15 days. New replies are no longer allowed.