1

I`m writing application with node and express. I want go compress my static files before sending them to the client with compression package. Here is my code:

var compression = require('compression'); var index = require('./routes/index'); var login = require('./routes/login'); var logout = require('./routes/logout'); var register = require('./routes/register'); var userRoute = require('./routes/user'); var app = express(); //files compression app.use(compression({ threshold: 0, filter: function () { return true; }, level: 0 })); 

I tried to use it without options but got the same result. I`m expecting to see Content-Encoding: gzip in response headers, but no luck.

enter image description here

But with debug I see that compression seem to be take place, is`t it? enter image description here

3
  • Level 0 is for "No compression". Commented Feb 12, 2017 at 14:16
  • Without options should be fine. Have you tried 'use'ing the compression on sub routes? Commented Feb 12, 2017 at 14:18
  • Set -1, then deleted all the options, size have't changed. I have't tried to use it in subroutes. Commented Feb 12, 2017 at 14:29

1 Answer 1

2

The level you are using means no compression as per documentation so choose -1 for default or best speed or best compression according to your demands

-1 Default compression level (also zlib.Z_DEFAULT_COMPRESSION). 0 No compression (also zlib.Z_NO_COMPRESSION). 1 Fastest compression (also zlib.Z_BEST_SPEED). 2 3 4 5 6 (currently what zlib.Z_DEFAULT_COMPRESSION points to). 7 8 9 Best compression (also zlib.Z_BEST_COMPRESSION). 
Sign up to request clarification or add additional context in comments.

1 Comment

Set -1, no changes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.