diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-27 00:03:35 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-27 00:03:35 +0000 |
| commit | 8beb37ed67b5f2fa0f9aa85499a8f11b39c9d067 (patch) | |
| tree | bd4b05a1e374b6cb10097bbcfbc12ef51c1cb85b /node_modules/express-minify-html/minifier.js | |
| parent | 5e73fe37c32faf821d3d16f0251007e366cb090b (diff) | |
need pull
Diffstat (limited to 'node_modules/express-minify-html/minifier.js')
| -rw-r--r-- | node_modules/express-minify-html/minifier.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/node_modules/express-minify-html/minifier.js b/node_modules/express-minify-html/minifier.js new file mode 100644 index 0000000..2428893 --- /dev/null +++ b/node_modules/express-minify-html/minifier.js @@ -0,0 +1,53 @@ +'use strict'; + +var minify = require('html-minifier').minify; + +function minifyHTML(opts) { + if (!opts) opts = {}; + + function minifier(req, res, next) { + + var sendMinified = function (callback) { + + // No callback specified, just minify and send to client. + if (typeof callback === 'undefined') { + return function (err, html) { + if (err) { + return next(err); + } + + html = minify(html, opts.htmlMinifier); + res.send(html); + } + } else { + + // Custom callback specified by user, use that one + return function (err, html) { + if (html) { + html = minify(html, opts.htmlMinifier); + } + + callback(err, html); + } + } + }; + + if (opts.override === false) { + res.renderMin = function (view, renderOpts, callback) { + this.render(view, renderOpts, sendMinified(callback)); + } + } else { + res.oldRender = res.render; + res.render = function (view, renderOpts, callback) { + this.oldRender(view, renderOpts, sendMinified(callback)); + }; + } + + return next(); + } + + return (minifier); +} + +module.exports = minifyHTML; + |
