Why Next.js images got expensive on Cloudflare: route them through /cdn-cgi/image and cache them
Meathill explains why the default /_next/image endpoint on OpenNext was uncacheable and rerun on every request, and replaces it with a custom loader to Cloudflare Image Transformations plus a long Cache Rule.
- Products
- WorkersImages
- Source
- Author experienceMeathill’s blog (meathill.com)
- Author
- Meathill (@meathill1)
Key points
- The author found /_next/image responses carried no Cache-Control, cf-cache-status, ETag or Last-Modified, so browsers and the CDN kept re-requesting and every image hit the Worker. Overriding it with Cache Rules did not take effect.
- Fix from the OpenNext docs: an image-loader.ts custom loader that emits /cdn-cgi/image/<options>/<src>, set as loader: "custom" in next.config. Responses then show unique_transformations_billing: true and respect Cache Rules.
- He then adds a Cache Rule forcing one-year edge and browser TTL on the image path, notes that LRU eviction can still drop cold images from edge caches, and suggests Cache Reserve if no re-transformation can be tolerated.
- Official docs (rechecked 2026-10-14): Images bills unique transformations once per calendar month; Free includes 5,000 and then returns error 9422 for new ones without charging; Paid includes 5,000, then $0.50 per 1,000. Cache Reserve needs a paid plan and bills storage plus Class A/B operations.
Original sources
Published
Why Next.js images got expensive on Cloudflare: route them through /cdn-cgi/image and cache them
Open original sourceMeathill explains why the default /_next/image endpoint on OpenNext was uncacheable and rerun on every request, and replaces it with a custom loader to Cloudflare Image Transformations plus a long Cache Rule.
The author shares the image-cost article on 𝕏.
Read on 𝕏Meathill
@meathill1 · Original 𝕏 post
Next.js <Image> 很好用,但在 Cloudflare Worker + OpenNext,默认图片优化可能悄悄变成“钱包黑洞”。 我帮朋友排查了一次每月近 $100 的账单,最后发现问题藏在 HTTP Header 里。 这篇文章记录了完整排查过程,以及如何用 Cloudflare 原生 Image Resizing + custom loader + 缓存规则,把成本优化下来,把性能提升上去。 https://t.co/3ULkkPFYl0
More to read
Cloudflare Recognizer
An open-source Workers + KV tool that polls Cloudflare analytics on a cron, tracks usage against a contract commit on a custom billing cycle, and alerts on surges, aimed at Enterprise accounts.
A voting page polling every three seconds: the author revises a $1,000 report.
@keking99 first reports about $1,000 for a voting page polling /api/result every three seconds. A later post reports $816.52 in accumulated usage as of October 4 and cites another screenshot total of $817.14. He later says his support ticket keeps being refused.
Idle projects can still bill: check background tasks and storage
@An_yhl reads @shmily7’s follow-up as a reason to audit abandoned AI projects: check scheduled background work and storage reads and writes, stop what is unused instead of just closing the page, and turn on alerts knowing they will not stop anything.