# express-hbsmin

> Express middleware (HTML minifier for Express Handlebars).

Latest version **0.1.4** (published 2020-04-10) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install express-hbsmin
pnpm add express-hbsmin
yarn add express-hbsmin
bun add express-hbsmin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2020-04-10 |
| First published | 2020-04-10 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | William Lim |
| Maintainers | wlwl2 |
| Keywords | express, hbs, minification, handlebars, minify, middleware, html, minifier |

## Links

- npm: https://www.npmjs.com/package/express-hbsmin
- Repository: https://github.com/wlwl2/express-hbsmin
- Homepage: https://github.com/wlwl2/express-hbsmin#readme
- Issues: https://github.com/wlwl2/express-hbsmin/issues
- npm.io page: https://npm.io/package/express-hbsmin

## Dependencies (2)

- [lodash.merge](https://npm.io/package/lodash.merge.md) 4.6.2
- [html-minifier](https://npm.io/package/html-minifier.md) 4.0.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2020-04-10
- 0.1.3 — 2020-04-10
- 0.1.2 — 2020-04-10
- 0.1.1 — 2020-04-10
- 0.1.0 — 2020-04-10

## README

# express-hbsmin

Express middleware (HTML minifier). Read the warning.

This is meant to be a heavily modified version of
https://github.com/melonmanchan/express-minify-html (@melonmanchan's
express-minify-html). Not sure if that will happen.

## Warning: Before you use this.

Causes problems with spacing (you possibly have to change css).
Load times are longer, but file size is smaller.

## Description

This express middleware simply enhances the regular 'render' method of the
response object for minifying HTML.

## Usage

```sh
npm install --save express-hbsmin
```

```js

const express = require('express')
const minifyHbs = require('express-hbsmin')

const app = express()

app.use(minifyHbs({
  override: true,
  exception_url: false,
  htmlMinifier: {
    removeComments: true,
    collapseWhitespace: true,
    collapseBooleanAttributes: true,
    removeAttributeQuotes: true,
    removeEmptyAttributes: true,
    minifyJS: 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 plugin. For
all the available configuration options, see [the original
repo!](https://github.com/kangax/html-minifier/blob/gh-pages/README.md)

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 `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.

```js

exception_url: [
    '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!

---
_Source: https://npm.io/package/express-hbsmin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
