NodeJS + ExpressJS Compression doing nothing?

compression, express, javascript, node.js

Solution

When turning compression on and off for testing make sure that you're doing a hard reload in chrome dev tools or otherwise you'll get a 'not-modified' response that is not compressed.

Your example code is working for me!

Problem

I have read that I should be compressing requests to my Node server, so I used npm to install the compression module, added it with require() to my server.js, then passed it in as a function to app.use. Then I looked at the network tab after, and I wanted to see how much the compression had saved me in kb. So I took the compression off, restarted my server, and it was the same amount of kb as with compression turned on? Here is my server.js ``` var express = require('express'), app = express(), path = require('path'), apiRouter = require('./app/routes/api'), mongoose = require('mongoose'), compression = require('compression'); app.use(compression()); app.use(express.static('public')); app.use('/api', apiRouter); app.use('*', function(req, res) { res.sendFile(path.join(__dirname + '/public/index.html')); }); mongoose.connect('mongodb://localhost/triviaattack'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function() { //Connected to DB successfully. }); app.listen(1337); ```

Original source

Related problems