Description
Is your feature request related to a problem?
When hosting a Next.js app via OpenNext on Cloudflare Workers I can’t control the Cache-Control headers for external images served through /_next/image?url=....
These images (e.g., from Google Cloud Storage) inherit short-lived headers (max-age=14400), and there’s no way to override them in the current OpenNext output. (or at least I coudn't)
This results in:
- Inefficient repeat loads
- Poor Lighthouse/PSI cache lifetime scores
- Unnecessary origin fetches
Describe the solution you'd like
I would like to see a way to intercept and modify responses (especially for /_next/image or custom proxied APIs) from within the generated Worker — ideally through a hook, middleware, or config.
This would help by allowing developers to:
- Set long-lived headers (max-age=31536000, immutable)
- Fully control caching strategy for remote image proxies
- Avoid Cloudflare’s transformation limits while maintaining performance
Describe alternatives you've considered
Use /cdn-cgi/image/https://...
— works, but requires enabling Cloudflare’s Remote Transformations product, which is limited to 5,000 images/month on the free tier.
Alternative 2:
Patch .open-next/server-functions/default/index.mjs
manually after build to override headers. This works but is fragile.
Alternative 3:
Proxy images through a Next.js API route like /api/image-proxy
, but cache headers from that are still hard to control cleanly when served via OpenNext’s Worker.
@opennextjs/cloudflare version
1.1.0
Additional context
The only scalable workaround right now is to manually patch the Worker after each build. Having first-class support for intercepting and customizing headers (especially for external image sources) would significantly improve developer experience, SEO, and cache hit ratio.
Before submitting
- I have checked that there isn't already a similar feature request
- This is a single feature (not multiple features in one request)