@itznotabug/appexpress-minifier

0.0.5 • Public • Published

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.

/@itznotabug/appexpress-minifier/

    Package Sidebar

    Install

    npm i @itznotabug/appexpress-minifier

    Weekly Downloads

    18

    Version

    0.0.5

    License

    Apache-2.0

    Unpacked Size

    5.62 kB

    Total Files

    3

    Last publish

    Collaborators

    • itznotabug