@itznotabug/appexpress-minifier
v0.0.5
Published
A content minifier middleware for AppExpress.
Downloads
8
Readme
AppExpress Minifier Middleware
This module allows basic minification to your outgoing responses.
Content with content-type
that contains text/
, application/json
and application/xml
are supported.
For detailed HTML minification options, refer to the html-minifier-terser documentation.
Installation
Add the middleware like this -
npm install @itznotabug/appexpress-minifier
Usage
// import
import AppExpress from '@itznotabug/appexpress';
import minifier from '@itznotabug/appexpress-minifier';
// setup
const express = new AppExpress();
express.middleware(minifier({
excludes: [
'/excludedPath', // direct path
/\.txt$/, /\.css$/ // or better, use a regex
],
htmlOptions: {
removeComments: true,
collapseWhitespace: true
}
}));
Excluding a particular request -
express.get('/dashboard', (_, res) => {
res.setHeaders({ 'exclude-minify': true });
res.render('dashboard.jsx', { props: buildProps() });
});
Suggestion: Middlewares in AppExpress
are executed in the order they are added, if you use multiple middlewares,
make sure to add this one at the end so that any content processing (if done by a middleware) is preformed on the full
content.