Skip to content

xettri/html-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Option type default description
css Boolean false To minify css of html
js Boolean false To minify js of html
comments Boolean true To remove comments from html
render Boolean true It will modify default response.render function for all
custom String null It will use to create the custom render function
debug Boolean false If 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

About

Middleware to compress the HTML content while serving.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published