Hi everyone,
I've noticed that Next.js doesn't gzip API route responses even when the Accept-Encoding: gzip header is included in the request. Here's what I've tested so far:
Environment:
Next.js versions: 14.1.0 and 15.0.4
Simple API route under the App Router, returning a JSON payload larger than 1KB.
Using curl to send requests with Accept-Encoding: gzip.
Issue:
Static files are gzipped as expected, but API route responses are not gzipped.
The Content-Encoding: gzip header is missing, and the response size remains uncompressed.
Reproduction Steps:
Create a simple API route:
export async function GET() {
const data = Array(5000).fill({ id: 1, name: "example" });
return new Response(JSON.stringify(data), {
headers: { "Content-Type": "application/json" },
});
}
Start the application in development mode using next dev.
Send a GET request using:
curl -H "Accept-Encoding: gzip" http://localhost:3000/api/example
Observe that the Content-Encoding header is missing, and the response size is uncompressed.
Question: Does Next.js rely on external tools like Nginx or a CDN for gzip compression in API routes? Or is there a built-in way to enable gzip compression for API responses?
Link to the code that reproduces this issue https://github.com/huseyinbuyukdere/temp-issue-gzip-next To Reproduce Start the application in development mode using next dev. Create an API route under...