expressjs / compression

Node.js compression middleware
MIT License
2.77k stars 241 forks source link

Compression not working in Heroku #146

Closed cythilya closed 6 years ago

cythilya commented 6 years ago

I have gzip when I run "yarn run dev" in local, but after I run "heroku local" or deploy my app to Heroku, gzip is gone. Below are my code snippet.

package.json

"compression": "^1.7.3",
"express": "4.16.2",

server.js

const server = express();
server.use(compression());

or view my repo and demo.

dougwilson commented 6 years ago

Can you provide a specific example URL to call so I can test the same one (since there are lots of URLs in that app)?

cythilya commented 6 years ago

Please view this url.

When I run in local "yarn run dev"

2018-09-12 10 09 28

After I deploy my app to Heroku

2018-09-12 10 10 04
dougwilson commented 6 years ago

Yea, I'm also not seeing it as compressed. Is there a way to attach a debugger into the running code on Heroku to see what is happening?

Avcajaraville commented 6 years ago

Same here, my assets are not being compressed and they are reported by google page speed as not compressed :)

CSS and JS files are being compress, everything else, is not. Weird.

Using:

"compression": "^1.7.3",
"express": "^4.16.3",
"node": "8.10.0"

Here is my site.

If you check the network panel, you'll see how the only assets being compressed are CSS & JS file. Fonts, svgs, etc are not.

This is how I use the module: captura de pantalla 2018-09-13 11 11 49

Thanks

Avcajaraville commented 6 years ago

Actually, this problem is not related to Heroku, as in local the same results are outputted on the network tab.

So, its reproducible also in local environments.

dougwilson commented 6 years ago

Hi @Avcajaraville sorry to hear you're having the same issue. I would live to debug through the issue to get to a resolution. Can you provide code and steps to reproduce so I can examine?

Avcajaraville commented 6 years ago

@dougwilson I just set a minimum gist that reproduces the issue here

As you can see, the css file is being gzip, while the svg is not: captura de pantalla 2018-09-13 18 58 38 captura de pantalla 2018-09-13 18 58 50

dougwilson commented 6 years ago

Ah, thanks @Avcajaraville ! This is because the SVG file in your example does not exceed the default value for the threshold option (https://github.com/expressjs/compression#threshold) which is 1kb. Responses below that threshold size are not compressed. You can lower the threadshold if you need it compressed 👍

Avcajaraville commented 6 years ago

Thanks a lot @dougwilson that was a super useful and quick answer :)

This is also the reason why this is not working for @cythilya.

We should read the docs more carefully :)

Really nice response time and great job with this module !!

dougwilson commented 6 years ago

It's no problem! Happy to help.