Back to Blog
Cloud NativeJuly 8, 20264 min read

Cloudflare Image Resizing: Optimizing Vercel Assets at the Edge

Learn how to use Cloudflare Image Resizing to optimize Vercel assets. Reduce origin load and boost performance with dynamic, edge-side image transformation.

CloudflareVercelImage OptimizationEdge ComputingWeb PerformanceNext.jsDeployment

Managing high-resolution assets on a Vercel-hosted application often leads to a classic trade-off: you either serve massive files that kill your Lighthouse scores, or you spend hours building a complex, server-side image processing pipeline. After struggling with bloated payloads on a high-traffic project, I found that offloading the heavy lifting to the edge is the most efficient way to handle dynamic image delivery.

By combining Vercel’s deployment speed with Cloudflare Image Resizing, you get on-the-fly transformations without maintaining a dedicated image server.

Why use Cloudflare Image Resizing for Vercel assets?

When you host assets on Vercel, they’re served from their global edge network. However, Vercel doesn't natively transform images on the fly in the same way specialized services do. If you need to serve a 200px thumbnail from a 5MB source image, you're either generating hundreds of variants at build time or burning your serverless execution time to process them.

Using Cloudflare Image Resizing allows you to perform these transformations at the edge, closer to the user. It’s a game-changer for Vercel asset optimization because it keeps your origin clean. You store the master image once, and Cloudflare handles the cropping, resizing, and format conversion (like WebP or AVIF) on demand.

The implementation flow

The architecture is straightforward. You point your requests to a Cloudflare Worker or a zone configured with Image Resizing enabled. Cloudflare fetches the image from your Vercel domain, transforms it, and caches the result.

Flow diagram: User → Request image Cloudflare Edge; Cloudflare Edge → Fetch original Vercel Origin; Cloudflare Edge → Transform/Resize CF; Cloudflare Edge → Deliver optimized User

Configuring the Edge Pipeline

First, ensure you have the "Image Resizing" add-on enabled in your Cloudflare dashboard. It requires a Business or Enterprise plan, which is a consideration if you're on a budget.

1. Enable Image Resizing

In your Cloudflare dashboard, navigate to Speed > Optimization > Image Resizing. Once enabled, Cloudflare can intercept requests based on URL patterns.

2. Handling the Request

You don't need to write custom code if you just want simple resizing parameters. You can request an image like this:

https://yourdomain.com/cdn-cgi/image/width=400,format=auto/path/to/image.jpg

Cloudflare will automatically pull image.jpg from your Vercel deployment, resize it to 400px, convert it to WebP or AVIF, and cache it.

3. Securing the Origin

A common mistake is leaving your Vercel origin open to the public internet for anyone to request raw, unoptimized images. I recommend using Cloudflare Workers Authentication: Securing Vercel Edge Middleware to ensure that only requests coming through your Cloudflare zone can access the original assets.

Comparison: Processing Strategies

StrategyCostPerformanceMaintenance
Build-time generationLowHighHigh
Vercel Serverless FunctionsHighMediumMedium
Cloudflare Image ResizingMediumVery HighLow

For most projects, the "Build-time" approach becomes a nightmare when you have thousands of user-generated images. Cloudflare’s edge image transformation approach is the sweet spot for developers who want to scale without managing infrastructure.

Lessons learned from production

I once tried to implement a custom sharp-based image processor inside a Vercel API route. It worked fine in development, but in production, it triggered constant cold starts and hit execution time limits, resulting in roughly a 30% failure rate for large image requests.

Switching to Cloudflare was a massive relief. It offloaded the CPU-intensive tasks entirely. If you're building a content-heavy platform, you might also find that Cloudflare Workers Geo-Routing: Dynamic Traffic Steering for Vercel helps ensure your image requests are being routed to the most performant origin regions.

A note on caching

Cloudflare caches the transformed images by default. However, if you update an image on Vercel with the same filename, you must purge the cache for that specific URL in Cloudflare, or users will see the stale, un-updated asset. I usually append a version hash or timestamp to the image URL during the build process to force a fresh fetch.

FAQ

Does Cloudflare Image Resizing work with any storage provider? Yes, as long as the origin (Vercel) returns the original image, Cloudflare can resize it. It doesn't care where the bytes come from.

Is serverless image processing cheaper than Cloudflare? Usually, no. While you pay for the Cloudflare add-on, you save significantly on Vercel compute costs and execution time limits.

Can I use this for non-Next.js projects? Absolutely. Since it works at the HTTP layer, it’s agnostic to your framework. Whether you're using static HTML or a complex SPA, the edge-side transformation works the same way.

If you're still hitting bottlenecks, sometimes the issue isn't the image transformation but the overall architecture of your frontend. If you need help structuring your app for better performance, I specialize in Next.js Website & Landing Page Development to ensure your assets and code are perfectly aligned.

The shift to edge-side processing is a significant step toward a truly performant web. It’s not just about saving bytes; it’s about reclaiming your time from managing image infrastructure. I’m still experimenting with caching headers to see how much further I can squeeze out of the TTL, but for now, this setup is rock solid.

Similar Posts