Browse Source

Minify responses

pm2
Luke Childs 8 years ago
parent
commit
d330f2d42d
  1. 4
      index.js
  2. 16
      lib/minify.js
  3. 2
      package.json

4
index.js

@ -3,6 +3,7 @@ const express = require('express');
const nunjucksFilters = require('./lib/nunjucks-filters'); const nunjucksFilters = require('./lib/nunjucks-filters');
const nunjucksMiddleware = require('./lib/nunjucks-middleware'); const nunjucksMiddleware = require('./lib/nunjucks-middleware');
const compression = require('compression'); const compression = require('compression');
const minify = require('./lib/minify');
const controllers = require('./controllers'); const controllers = require('./controllers');
const app = express(); const app = express();
const port = process.env.port || 3000; const port = process.env.port || 3000;
@ -15,6 +16,9 @@ app.use(nunjucksMiddleware);
// Compress responses // Compress responses
app.use(compression()); app.use(compression());
// Minify responses
app.use(minify);
// Page routes // Page routes
app.get('/', controllers.listing); app.get('/', controllers.listing);
app.get('/node/:id', controllers.node); app.get('/node/:id', controllers.node);

16
lib/minify.js

@ -0,0 +1,16 @@
const minify = require('express-minify');
const minifyHTML = require('express-minify-html');
module.exports = [
minify(),
minifyHTML({
htmlMinifier: {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true,
removeOptionalTags: true
}
})
];

2
package.json

@ -6,6 +6,8 @@
"dependencies": { "dependencies": {
"compression": "^1.6.2", "compression": "^1.6.2",
"express": "^4.14.0", "express": "^4.14.0",
"express-minify": "^0.2.0",
"express-minify-html": "^0.6.0",
"moment": "^2.14.1", "moment": "^2.14.1",
"nunjucks": "^2.5.0", "nunjucks": "^2.5.0",
"onionoo": "^0.5.0", "onionoo": "^0.5.0",

Loading…
Cancel
Save