JamesE
JamesE

Reputation: 3923

Express 4 Compression

I am following the simple guide in the npm compression module, but I'm not seeing compression on my static pages. It does look like the pages being redered by Express are being compressed. Is there something I need to do to get the static files compressed as well?

I am using Express 4.2.0 and Compression 1.0.8.

var express = require('express');
var compression = require('compression');

var app = express();
app.use(compression());

Here is one of my router functions:

router.get('/:name', function(req, res) {
        res.render('test/blah/' + req.params.name, {
        title : entry.title
    });
}

Upvotes: 2

Views: 2063

Answers (1)

vodolaz095
vodolaz095

Reputation: 6986

in your middleware chain try to use compress middleware before the static middleware

app.use(compression());
app.use(express.static(__dirname+'/public'));

Upvotes: 3

Related Questions