We’re big fans of Cloudflare workers! Recently we realized that a lot of the images on our website were way too large, potentially impacting page load times and SEO rankings, so we implemented site-wide image optimization in a Cloudflare worker.
I ran into issues (trade-offs) when trying to do this with Cloudflare images, or Cloudflare image resizing, so I ended up using Cloudinary instead (their free plan), to make sure all images are fully optimized, and it enabled me to serve some legacy animated GIFs as MP4 and WebM formats too.
I think it worked out pretty well:
- Since its implemented fully in the worker, no changes were needed to our website
- It serves modern (small!) image formats to all browsers that support it: AVIF, WebP
- It scales all images based on device type (desktop, tablet, mobile)
- No manual steps required for images, no uploading of images ahead of time, and images keep their original filenames
- Great perf, images are still served from the primary domain name, eliminating additional DNS lookup(s) and HTTPS connect time
- We’re able to easily stay within the free tiers for both Cloudinary and Cloudflare
Would love your feedback and to hear how you tackled this issue!