Reputation: 100
I have the following simple server written in Expressjs
'use strict';
var express = require('express');
var app = express();
var compression = require('compression');
app.use(compression());
app.listen(process.env.PORT || 3030);
app.use(express.static(__dirname + '/_site', {
maxAge: '365d'
}));
console.log('server running');
However, while my index.html
page is served gzipped, none of the link
'ed files or script
files are (such as css, or js files):
Is there something I've done wrong here?
Thanks.
Upvotes: 5
Views: 1224
Reputation: 619
I came across this as well, maybe this may have come somewhat late but here goes. It seems to be like this, the compression only seems to engage for files that are of a certain size which kind of makes sense since there are some files that are not worth the time to do so.
As you cab see in the screen capture, only the big CSS files are compressed. The smaller ones are left alone. Before you ask, yes all the files are served from the public folder and not CDN.
My code:
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
// Compress content
app.use(compression({
level: 9,
memLevel: 9
}));
Upvotes: 1