Express gzip static content

HyderA picture HyderA · Jun 16, 2011 · Viewed 33k times · Source

Express and connect appeared to have removed their gzip functions because they were too inefficient. Are there any reliable solutions to gzip with express-js currently?

Answer

gasolin picture gasolin · Mar 10, 2013

Express 3.0 now has compress() support:

var app = express();
// gzip
app.use(express.compress());
// static
app.use("/public", express.static(__dirname + '/public'));
// listen
app.listen(80);

EDIT for Express 4.0, compress become the separate middleware. So you have to install and import to use it:

var compress = require('compression');
app.use(compress());