Giter Club home page Giter Club logo

html-minifier's Introduction

Koa HTML Minifier

Middleware that minifies your HTML responses using html-minifier-terser. It uses html-minifier-terser's default options which are all turned off by default, so you have to set the options otherwise it's not going to do anything.

NPM version Build status Test coverage License

Install

# npm ..
npm i koa-html-minifier
# yarn ..
yarn add koa-html-minifier

API

// do compression stuff first
app.use(require('koa-compress')());

// then use this minifier
app.use(require('koa-html-minifier')({
  collapseWhitespace: true
}));

Options

See: https://github.com/DanielRuf/html-minifier-terser#options-quick-reference

Contributors

Name Website
Jonathan Ong http://jongleberry.com
Imed Jaberi https://www.3imed-jaberi.com/
João Carmona

html-minifier's People

Contributors

3imed-jaberi avatar dependabot[bot] avatar greenkeeperio-bot avatar haoxins avatar jonathanong avatar jpsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

html-minifier's Issues

koa2 support

Is there any plans to support koa2?

I've forked this repo and done the changes myself. All the (adapted to koa2) tests passed.
I don't know what to do next in order to, maybe, have my changes merged in this repo.
Should I push my local "koa2" branch to my forked repo and make the pull request from there?
This is my first time doing this so, please, apologize me for doing such a stupid issue.

Minify static files from koa-static?

I'm hoping to minify static files that come from koa-static, however koa-html-minifier doesn't seem to be minifying. 🤔

This is what I've got,

const serve = require('koa-static');

...

// compression
app.use(require('koa-compress')());

// minifier
app.use(require('koa-html-minifier')({
  collapseWhitespace: true
}));

// static server
app.use(serve('public'));

And, the resulting code that I see in the browser is still not minified.

NOTE: I also have a REST API with koa-router, but I don't think that should make a difference.

Thanks!

Wrap minify with try/catch

Prevent server down if minify throws error:

    let body = ctx.response.body;

    try {
      body = await minify(ctx.response.body, options);
    } catch (error) {
       errorCallback(error)
    }

    ctx.response.body = body;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.