
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
express-minify-html-2
Advanced tools
Express middleware wrapper around html-minifier-terser
This fork is made in order to keep the express-minify-html project alive. All credits go to the contributors in the original repo.
This express middleware simply enchances the regular 'render' method of the response object for minifying HTML.
npm install --save --production express-minify-html-2 express
var express = require('express')
var minifyHTML = require('express-minify-html-2')
var app = express()
app.use(
minifyHTML({
override: true,
/**
* exceptionUrls can also be spelled as exception_url for backwards compatibility
*/
exceptionUrls: false,
htmlMinifier: {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true,
},
}),
)
app.get('hello', function (req, res, next) {
res.render('helloTemplate', { hello: 'world' }, function (err, html) {
// The output is minified, huzzah!
console.log(html)
res.send(html)
})
})
Set 'override' to false if you don't want to hijack the ordinary res.render function. This adds an additional res.renderMin function to the response object to render minimized HTML.
The 'htmlMinifier' opts are simply passed on to the html-minifier-terser
plugin. For all the available configuration
options, see the original repo!
If no callback is provided, res.render/res.renderMin sends the minified HTML to the client just as the regular express res.render does. Otherwise, the callback is called with the error object and the minified HTML content, as demonstrated above.
the exceptionUrls
(or it's alias exception_url
) optional parameter is a single value, or an array of strings, regexes and functions
that can be used to check whether minifying should be skipped entirely.
exceptionUrls: [
'url_to_avoid_minify_html', // String.
/regex_to_analyze_req_to_avoid_minify/i, // Regex.
function (req, res) {
// Function.
// Code to analyze req and decide if skips or not minify.
// Needs to return a boolean value.
return true
},
]
Full examples can naturally be found under the 'examples'-folder of this repository!
The code inside minifier.js should be compatible with nodejs 6.0.0,
but since html-minifier-terser
requires "^14.13.1" the package also requires at least nodejs 14.0.0
MIT © Matti Jokitulppo
FAQs
Express.js middleware wrapper around html-minifier-terser
We found that express-minify-html-2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.