Skip to content

Compression 1.8.0 does not work with Express 4.21.2 #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oliver-moran opened this issue Mar 26, 2025 · 4 comments
Closed

Compression 1.8.0 does not work with Express 4.21.2 #224

oliver-moran opened this issue Mar 26, 2025 · 4 comments

Comments

@oliver-moran
Copy link

oliver-moran commented Mar 26, 2025

Environment information

Version: Compression 1.8.0 with Express 4.21.2.

Platform:

Node.js version: v18.19.1 and v22.13.0

Any other relevant information:

index.js

const express = require("express");
const compression = require("compression");

const app = express();
app.use(compression());
app.use(express.static("public"));  // serve static files from public folder

app.listen(8000, () => {
    console.log("Server is running on http://localhost:8000");
});

package.json:

{
  ...
  "dependencies": {
      "compression": "^1.7.5",
      "express": "^4.21.2"
  }
}

The above will install compression 1.8.0 and files served will not be compressed. Uninstalling compression and reinstalling it at 1.7.5 will fix the problem:

npm uninstall compression --save
npm install [email protected] --save
@ShubhamOulkar
Copy link
Member

Hi @oliver-moran, could you please update the threshold value as follows?

app.use(compression({ threshold:0, }));

This ensures that all responses, regardless of size, are compressed. If this doesn't work as expected, could you check the response headers and share them here? Specifically, look for the Content-Encoding and Vary headers to verify if compression is applied.

@oliver-moran
Copy link
Author

oliver-moran commented Mar 27, 2025

Fresh test case but specifying { threshold:0, }:

HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Thu, 27 Mar 2025 21:32:32 GMT
ETag: W/"eb1-195d98564a8"
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Content-Encoding: br
Date: Thu, 27 Mar 2025 21:33:09 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked

Uninstalling Compression and reinstalling @1.7.5:

HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Thu, 27 Mar 2025 21:32:32 GMT
ETag: W/"eb1-195d98564a8"
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Content-Encoding: gzip
Date: Thu, 27 Mar 2025 21:35:59 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked

OK. I see it. So Brotli is default now? 🤦

@bjohansebas
Copy link
Member

Yep, now Brotli is the default.

@oliver-moran
Copy link
Author

I'll see myself out...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants