1.0.1 • Published 5 years ago

html-compressor v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

html-compressor

npm version npm license npm repository npm author

html-compressor

Middleware to compress the HTML content while serving.

Installing

NPM

Using npm:

$ npm install html-compressor

Method

var express = require('express');
var htmlCompressor = require("html-compressor");
var app = express();
app.use(htmlCompressor());

Options

app.use(htmlCompressor(<options>));

default options>>

  • remove comments
  • remove white space
  • remove empty attributes
  • remove attribute quotes
  • collapse Boolean attribute

These default options are able to minify the html content but for css and js we can pass the option for that.

Optiontypedefaultdescription
cssBooleanfalseTo minify css of html
jsBooleanfalseTo minify js of html
commentsBooleantrueTo remove comments from html
renderBooleantrueIt will modify default response.render function for all
customStringnullIt will use to create the custom render function
debugBooleanfalseIf true, then it will show the message when unable to minify html due to error

Default Compress Function (renderCompress)>> renderCompress is default compress function we can use response.renderCompress to render compress html

example

var express =  require('express');
var htmlCompressor = require("html-compressor");
var app = express();
app.use(htmlCompressor(
	js : true,
	css : true,
	custom : 'customRender',
	render : true
));

app.get('/modified_render',  function  (req,  res,  next)  {
	res.render('viewfile',  {});
}

app.get('/default_compressor_render',  function  (req,  res,  next)  {
	res.renderCompress('viewfile',  {});
}

app.get('/custom_render',  function  (req,  res,  next)  {
	res.customRender('viewfile',  {});
}

licence

MIT licence

Author

@BCrazyDreamer