#Next.js API Route Responses Not Gzipped Despite Accept-Encoding Header

2 messages · Page 1 of 1 (latest)

brisk arrow
#

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?

https://github.com/vercel/next.js/issues/73695

GitHub

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...

fair swanBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)