Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minify all of sails.js served html

Tags:

sails.js

I need my sails.js app to serve minified html to the user. So it is hard to read by the user. Has anyone done this before ?

Thank you.

like image 493
Sahan Avatar asked Sep 26 '14 02:09

Sahan


1 Answers

This works for me: https://github.com/balderdashy/sails/issues/2188#issuecomment-56994236

In config/views.js:

var minify = require('html-minifier').minify;
var ejs = require('ejs-locals');
var parsing = function(path,options,fn) {
    options.locals = options.locals || {};
    options.locals._layoutFile = 'layout.ejs';
    ejs(path, options, function(err, str){
      str = minify(str,{collapseWhitespace: true, removeComments: true});
      return fn(err, str);
    });

};

module.exports.views = {
  engine: {
    ext: 'ejs',
    fn: parsing
  },
  layout: false
};
like image 128
Marcelo Boeira Avatar answered Jan 08 '23 11:01

Marcelo Boeira