Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ As of version 5.0.0, all notable changes to HTML Minifier (HM) are documented in

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.1.0] - 2026-11-11

### Fixed

* Fixed `removeUnusedCSS` keeping style sheets of which nothing is used as written, unminified, where they held a word of ten or more lowercase letters (e.g., `background`; taken for a custom-fragment placeholder)
* Fixed `mergeScripts` merging what only looks like scripts—text in `textarea` and `title` elements, comments, and markup kept with `htmlmin:ignore`—and losing code where a script holds `<!--<script>`, which browsers end only at a later `</script>` (e.g., `<script><!--<script></script><script></script></script>` lost `<script></script>`)
* Fixed `mergeScripts` joining a script that ends in a custom fragment on one line with the next, which the fragment may comment out
* Fixed `mergeScripts` dropping the attributes of scripts merged into another, whose own attributes then covered their code, too—which tools that rewrite pages in the browser or at the edge read (e.g., `data-cfasync="false"` for Cloudflare Rocket Loader, or `data-cookieconsent`)—scripts now merge only where their attributes match (other than a JavaScript `type`), and not where they have an `id`

### Added

* Added `mergeStyles` (part of the `comprehensive` preset) to merge consecutive `style` elements with compatible style sheets into one, which `minifyCSS` then minifies as one (e.g., `<style>a{color:red}</style><style>a{color:blue}</style>` becomes `<style>a{color:#00f}</style>`)

### Changed

* Made `mergeScripts` faster, as it merges what the minifier writes rather than scanning its output again

## [5.0.4] - 2026-11-11

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
| `keepClosingSlash`<br>`--keep-closing-slash` | Keep the trailing slash on void elements and other start tags that carry one, and read it as closing the element | `false` |
| `maxInputLength`<br>`--max-input-length` | Maximum input length to prevent ReDoS attacks (disabled by default) | `undefined` |
| `maxLineLength`<br>`--max-line-length` | Specify a maximum line length; output will be split by newlines in tags only (between attributes or before a tag’s `>`), where they can’t change the page, so lines may run longer | `undefined` |
| `mergeScripts`<br>`--merge-scripts` | Merge consecutive inline `script` elements into one (only merges compatible scripts with same `type`, matching `async`/`defer`/`nomodule`/`nonce`) | `false` |
| `mergeScripts`<br>`--merge-scripts` | Merge consecutive `script` elements into one (only merges classic scripts whose attributes match, and none with an `id`) | `false` |
| `mergeStyles`<br>`--merge-styles` | Merge consecutive `style` elements into one (only merges style sheets whose attributes match, and none with an `id`) | `false` |
| `minifyCSS`<br>`--minify-css` | [Minify CSS](#css-minification) in `style` elements and attributes (uses [Lightning CSS](https://lightningcss.dev/)) | `false` (could be `true`, `Object`, `Function(text, type)`) |
| `minifyJS`<br>`--minify-js` | [Minify JavaScript](#javascript-minification) in `script` elements and event attributes (uses [Terser](https://terser.org/) or [SWC](https://swc.rs/)) | `false` (could be `true`, `Object`, `Function(text, inline)`) |
| `minifyJSON`<br>`--minify-json` | [Minify JSON](#json-minification) in `script` elements (e.g., `application/ld+json`, `importmap`, etc.) by removing whitespace | `false` |
Expand Down
1 change: 1 addition & 0 deletions backtest/html-minifier.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"maxInputLength": 0,
"maxLineLength": 0,
"mergeScripts": true,
"mergeStyles": true,
"minifyCSS": true,
"minifyJS": {
"engine": "swc"
Expand Down
4 changes: 4 additions & 0 deletions demo/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const demoConfig = {
label: 'Merge scripts',
checked: true
},
mergeStyles: {
label: 'Merge styles',
checked: true
},
minifyCSS: {
label: 'Minify CSS',
checked: false,
Expand Down
6 changes: 5 additions & 1 deletion html-minifier.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@
"minimum": 0
},
"mergeScripts": {
"description": "Merge consecutive inline `script` elements into one",
"description": "Merge consecutive `script` elements into one",
"type": "boolean"
},
"mergeStyles": {
"description": "Merge consecutive `style` elements into one",
"type": "boolean"
},
"minifyCSS": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@
},
"type": "module",
"types": "dist/types/htmlminifier.d.ts",
"version": "5.0.4"
"version": "5.1.0"
}
Loading
Loading