breezewish / express-minify

Automatically minify and cache your javascript and css files.
https://npmjs.org/package/express-minify
MIT License
86 stars 18 forks source link

Basic Usage is not working #51

Closed michaelfranzl closed 7 years ago

michaelfranzl commented 7 years ago

express-minify needs a Content-Type header on the response before it does anything. Express doesn't set this by default, so one needs a custom middleware before the express-minify middleware.

So your Basic Usage example should be extended in the following way so that it works 'out of the box', to save developers some time debugging.

var mime = require('mime');
app.use(function (req, res, next) {
  res.type(mime.lookup(req.path));
  next();
});
app.use(minify());

I'm using express 4.14.0 and express-minify 0.2.0.

Martii commented 7 years ago

What node version? Also we have no code like this and express-minify is working. Obviously we modify the Content-Type when we need but I've never seen this requirement of your code snippet.

michaelfranzl commented 7 years ago

Node 6.9.4. I debugged some more and found out that my issue had to do with caching. When express decides to send a 304 Not modified, the Content-Type header is undefined. The Basic Usage example works. Sorry for the noise.