
Research
/Security News
Compromised npm Packages in the AsyncAPI Namespace Deliver Miasma Botnet Loader
4 compromised asyncapi packages deliver miasma botnet loader on macOS, Linux and Windows.
minify-html-css
Advanced tools
🔽 A JavaScript (TypeScript) library to minify HTML and CSS.
I created this project to bring together the most performant HTML and CSS minifier libraries (according to my tests and findings) as clean, easy-to-use functions with well-documented options. The goal is to make web minification accessible, fast, and developer-friendly.
npm install minify-html-css
import { minifyHTML } from 'minify-html-css';
const html = `
<div>
<!-- This is a comment -->
<h1> Hello World! </h1>
<style>
body { color: red; }
</style>
</div>
`;
const result = minifyHTML(html).code;
console.log(result); // "<div><h1>Hello World!</h1><style>body{color:red}</style></div>"
import { minifyCSS } from 'minify-html-css';
const css = `
/* page styles */
:root { --main-color: red; }
body {
color: var(--main-color);
margin: 0;
line-height: 1.4;
}
`;
const result = minifyCSS(css).code;
console.log(result); // ":root{--main-color:red}body{color:var(--main-color);margin:0;line-height:1.4}"
minifyHTML(input: string, options?: MinifyHTMLOptions): TransformOutputMinifies an HTML string (whitespace, comments, attributes, inline assets depending on options).
Returns the underlying @swc/html minifier result. In practice you’ll primarily use:
code: the minified HTMLerrors: an array of parse/minification errors (if any)Implementation note: This is a small wrapper around
@swc/html(SWC’s HTML minifier).
input (string): HTML to minify.options? (MinifyHTMLOptions): Optional configuration.This package keeps the inline docs for options in the type files (with full JSDoc and defaults). Start here:
src/minify-html-types.ts (HTML options + MinifierType)import { minifyHTML } from 'minify-html-css';
const input = `
<div>
<!-- hi -->
Again
</div>
`;
// Keep HTML comments
const result = minifyHTML(input, { removeComments: false }).code;
console.log(result); // <div><!-- hi -->Again</div>
minifyCSS(input: string, options?: MinifyCSSOptions): TransformResultMinifies CSS using Lightning CSS.
Returns the underlying lightningcss transform result, with one convenience tweak: code is returned as a string (not a Buffer).
Implementation note: This is a wrapper around
lightningcss.
input (string): CSS to minify.options? (MinifyCSSOptions): Optional configuration.See the full option surface (typed + documented) here:
import { minifyCSS, minifyHTML } from 'minify-html-css';
const input = `
body {
color: red;
}
@keyframes slidein {
from {
transform: translateX(0%);
}
to {
transform: translateX(100%);
}
}
`;
// Remove unused @keyframes 'slidein'
const result = minifyCSS(input, { unusedSymbols: ['slidein'] }).code;
console.log(result); // body{color:red}
This package also ships a CLI binary named minify-html-css.
Run via npx (no global install):
npx minify-html-css -i input.html -o output.html
npx minify-html-css -i styles.css -o styles.min.css
Or install globally:
npm install -g minify-html-css
minify-html-css -i input.html -o output.html
Options:
-i, --input <file>: input file path (alternatively you can pass the input file as the first positional argument)-o, --output <file>: output file path (if omitted, prints to stdout)-t, --type <html|css>: file type (auto-detected from extension if omitted)-h, --help: show help-v, --version: show versionExamples:
# Auto-detect file type from extension
minify-html-css index.html > index.min.html
# Force type when extension can't be detected
minify-html-css -i input -t html > output.html
minifyHTML) built on top of @swc/htmlminifyCSS) built on top of lightningcssWe welcome contributions!
Requirements:
Steps:
git switch -c my-featurebun run lint && bun test (This is automatically done when you open a pull request) to ensure everything passes.git commit -m "Add my feature"Please read our CONTRIBUTING.md for more details.
This project is licensed under the MIT License.
Types License Notice:
src/minify-html-types.ts are adapted from the SWC Project and are licensed under the Apache License, Version 2.0.@swc/html under the hood for actual HTML minification.FAQs
🔽 A library to minify HTML and CSS.
We found that minify-html-css demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
/Security News
4 compromised asyncapi packages deliver miasma botnet loader on macOS, Linux and Windows.

Research
/Security News
A compromised jscrambler npm release added a malicious preinstall hook that runs hidden native binaries on Linux, macOS, and Windows.

Research
/Security News
A malicious .NET package is typosquatting the Braintree SDK to steal live payment card data, merchant API keys, and host secrets from production apps.