5

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):

Chrome Audits Tab

Is there something I've done wrong here?

Thanks.

1
  • how did you get the "enable gzip compression" recommendation block? Commented Jun 16, 2017 at 19:00

1 Answer 1

1

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.

Express JS compressed and uncompressed css files

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 })); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.