Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-minifier-terser

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-minifier-terser

Highly configurable, well-tested, JavaScript-based HTML minifier.

  • 7.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.5M
decreased by-18.77%
Maintainers
2
Weekly downloads
 
Created

What is html-minifier-terser?

The html-minifier-terser npm package is a tool to minify HTML files. It removes unnecessary whitespace, comments, and other unneeded characters without changing the functionality of the HTML. This results in smaller file sizes which can lead to faster page load times. It is a fork of the original html-minifier package, updated to use Terser for JavaScript minification, which supports ES6+ syntax.

What are html-minifier-terser's main functionalities?

Minify HTML

This feature collapses whitespace between tags in the HTML, resulting in a smaller file size.

const htmlMinifier = require('html-minifier-terser');
const result = htmlMinifier.minify('<p>      Some text    </p>', { collapseWhitespace: true });
console.log(result); // Output: '<p>Some text</p>'

Remove Comments

This feature removes HTML comments from the file, which are not needed for functionality and can reduce file size.

const htmlMinifier = require('html-minifier-terser');
const result = htmlMinifier.minify('<!-- This is a comment --> <div>Content</div>', { removeComments: true });
console.log(result); // Output: '<div>Content</div>'

Minify JavaScript

This feature minifies any JavaScript within <script> tags in the HTML, using Terser for advanced JavaScript minification.

const htmlMinifier = require('html-minifier-terser');
const result = htmlMinifier.minify('<script>var a = 1; var b = 2; var c = a + b;</script>', { minifyJS: true });
console.log(result); // Output: '<script>var a=1,b=2,c=a+b;</script>'

Minify CSS

This feature minifies any CSS within <style> tags or style attributes in the HTML.

const htmlMinifier = require('html-minifier-terser');
const result = htmlMinifier.minify('<style>body { font-size: 20px; color: #000000; }</style>', { minifyCSS: true });
console.log(result); // Output: '<style>body{font-size:20px;color:#000}</style>'

Remove Optional Tags

This feature removes optional closing tags like </head>, </body>, and sometimes <html> to further reduce the file size.

const htmlMinifier = require('html-minifier-terser');
const result = htmlMinifier.minify('<html><head><title>Title</title></head><body><p>Text</p></body></html>', { removeOptionalTags: true });
console.log(result); // Output: '<title>Title</title><p>Text</p>'

Other packages similar to html-minifier-terser

Keywords

FAQs

Package last updated on 11 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc