Guidance needed for configuring Next.js 15 streaming with Fastly CDN #81676
Replies: 1 comment 1 reply
-
Here’s detailed guidance for configuring Next.js 15 streaming with Fastly CDN to ensure streaming responses work correctly without buffering: Background The CDN must not buffer the entire response. Transfer-Encoding must be chunked and passed through. Compression (gzip, brotli) must be compatible with streaming or disabled. Key Fastly Configuration Tips
Make sure beresp.do_stream = true is set before any gzip or content transformations.
Content-Type: text/html; charset=utf-8 Cache-Control headers Content-Encoding (if compression is enabled) Ensure Fastly does not strip or modify these headers improperly. Add this in vcl_deliver to preserve headers:
To disable buffering explicitly for Next.js responses:
Note: Setting beresp.do_pass disables caching for that response. Use only if acceptable or for specific streaming pages.
Prefer disabling gzip on Fastly for streaming responses, or Use Next.js’s built-in compression and let Fastly pass through compressed streams transparently (less common). If you disable gzip at Fastly, confirm Next.js is not double compressing.
For dynamic streaming SSR pages, consider setting Cache-Control: no-store or private to avoid caching. For static assets, allow caching as normal. Known Limitations & Tips Test streaming behavior with simple streaming endpoints first (e.g., a minimal streaming HTML endpoint). Use browser devtools to confirm chunks arrive progressively. Some clients or browsers might also buffer; verify using curl or tools like httpie.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
We are adopting Next.js 15 to leverage its server-side streaming capabilities with React Suspense. While streaming works perfectly in our local development environment, we are encountering issues when deploying our application behind Fastly CDN.
The Problem
When a page with Suspense boundaries is requested through Fastly, the response appears to be fully buffered. Instead of the initial shell being sent immediately followed by streamed chunks, the browser only receives the complete HTML document after the slowest data fetch has resolved on the server. This behavior negates the primary user experience benefit of streaming.
Expected Behavior
We expect Fastly to act as a pass-through for the streamed response from the Next.js server. The initial HTML shell should be delivered to the client instantly, and subsequent chunks generated by resolved Suspense boundaries should be sent as they become available, without being buffered by the CDN.
Our Setup
What We've Tried
set beresp.do_stream = true;
withinvcl_fetch
for responses from our Next.js origin.Transfer-Encoding: chunked
.Request for Guidance
Could the team provide official documentation or guidance on the recommended configuration for using Next.js streaming with a streaming-capable CDN like Fastly?
Specifically, we are looking for answers to the following:
Any insights or examples would be immensely helpful for us and likely for other users in the community deploying Next.js in similar enterprise environments.
Thank you for your time and for building a great framework.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions