Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express 4.x compression

I have tested my local web server with Google's PageSpeed chrome extension. One of the results was that my web server doesn't have compression enabled. I am using node js on the backend with express 4.x. I googled a bit to find a solution to compress data and I found https://github.com/expressjs/compression a middleware for express. I tried to use it like this:

    var app                 = express();
    var compression         = require('compression');
    var server              = http.createServer(app);
    server.listen(CONFIG.PORT);
    app.use(compression());

Even though I did this pageSpeed is still recommending to compress data. What am I doing wrong?

like image 380
exilonX Avatar asked Feb 09 '15 09:02

exilonX


Video Answer


1 Answers

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

Put JS, CSS, HTML files below the public directory and they will be compressed.

like image 180
Mark Avatar answered Oct 19 '22 13:10

Mark