html-minifier-next 4.19.0 → 4.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,9 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright 2010–2019 Juriy “kangax” Zaytsev
4
-
5
4
  Copyright Terser
6
-
7
5
  Copyright 2025 Jens Oliver Meiert
8
6
 
9
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/html-minifier-next.svg)](https://www.npmjs.com/package/html-minifier-next) [![Build status](https://github.com/j9t/html-minifier-next/workflows/Tests/badge.svg)](https://github.com/j9t/html-minifier-next/actions) [![Socket](https://badge.socket.dev/npm/package/html-minifier-next)](https://socket.dev/npm/package/html-minifier-next)
4
4
 
5
- HTML Minifier Next (HMN) is a **super-configurable, well-tested, JavaScript-based HTML minifier** that can also handle in-document CSS, JavaScript, and SVG minification.
5
+ Your HTML precision tool: HTML Minifier Next (HMN) is a **super-configurable, well-tested, JavaScript-based HTML minifier** able to also handle in-document CSS, JavaScript, and SVG minification.
6
6
 
7
7
  The project was based on [HTML Minifier Terser (HMT)](https://github.com/terser/html-minifier-terser), which in turn had been based on [Juriy “kangax” Zaytsev’s HTML Minifier (HM)](https://github.com/kangax/html-minifier); as of 2025, both HTML Minifier Terser and HTML Minifier had been unmaintained for several years. HMN offers additional features and has been optimized for speed. While an independent project, it is still backwards-compatible with HMT and HM.
8
8
 
@@ -87,10 +87,10 @@ console.log(result); // “<p title=example id=moo>foo”
87
87
  CommonJS:
88
88
 
89
89
  ```javascript
90
- const { minify, getPreset } = require('html-minifier-next');
90
+ const { minify } = require('html-minifier-next');
91
91
 
92
92
  (async () => {
93
- const result = await minify('<p title="example" id="moo">foo</p>', getPreset('comprehensive'));
93
+ const result = await minify('<p title="example" id="moo">foo</p>', { preset: 'comprehensive' });
94
94
  console.log(result); // “<p id=moo title=example>foo”
95
95
  })();
96
96
  ```
@@ -101,8 +101,8 @@ See [the original blog post](https://perfectionkills.com/experimenting-with-html
101
101
 
102
102
  HTML Minifier Next provides presets for common use cases. Presets are pre-configured option sets that can be used as a starting point:
103
103
 
104
- * `conservative`: Safe minification suitable for most projects. Includes whitespace collapsing, comment removal, and doctype normalization.
105
- * `comprehensive`: More aggressive minification for better file size reduction. Includes relevant conservative options plus attribute quote removal, optional tag removal, and more.
104
+ * `conservative`: Basic minification with whitespace collapsing, comment removal, and removal of select attributes.
105
+ * `comprehensive`: More advanced minification for better file size reduction, including relevant conservative options plus attribute quote removal, optional tag removal, and more.
106
106
 
107
107
  To review the specific options set, [presets.js](https://github.com/j9t/html-minifier-next/blob/main/src/presets.js) lists them in an accessible manner.
108
108
 
@@ -130,8 +130,8 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
130
130
 
131
131
  | Option (config/CLI) | Description | Default |
132
132
  | --- | --- | --- |
133
- | `cacheCSS`<br>`--cache-css` | Set CSS minification cache size; higher values improve performance for batch processing | `500` (or `1000` when `CI=true`) |
134
- | `cacheJS`<br>`--cache-js` | Set JavaScript minification cache size; higher values improve performance for batch processing | `500` (or `1000` when `CI=true`) |
133
+ | `cacheCSS`<br>`--cache-css` | Set CSS minification cache size; higher values improve performance for batch processing | `500` |
134
+ | `cacheJS`<br>`--cache-js` | Set JavaScript minification cache size; higher values improve performance for batch processing | `500` |
135
135
  | `caseSensitive`<br>`--case-sensitive` | Treat attributes in case-sensitive manner (useful for custom HTML elements) | `false` |
136
136
  | `collapseAttributeWhitespace`<br>`--collapse-attribute-whitespace` | Trim and collapse whitespace characters within attribute values | `false` |
137
137
  | `collapseBooleanAttributes`<br>`--collapse-boolean-attributes` | [Omit attribute values from boolean attributes](https://perfectionkills.com/experimenting-with-html-minifier/#collapse_boolean_attributes) | `false` |
@@ -183,7 +183,7 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
183
183
 
184
184
  ### Sorting attributes and style classes
185
185
 
186
- Minifier options like `sortAttributes` and `sortClassName` won’t impact the plain‑text size of the output. However, using these options for more consistent ordering improves the compression ratio for gzip and Brotli used over HTTP.
186
+ Minifier options like `sortAttributes` and `sortClassName` won’t impact the plain‑text size of the output. However, using these options for more consistent ordering improves the compression ratio for Gzip and Brotli used over HTTP.
187
187
 
188
188
  ### CSS minification
189
189
 
@@ -295,8 +295,8 @@ const result = await minify(html, {
295
295
  minifyCSS: true,
296
296
  minifyJS: true,
297
297
  // Configure cache sizes (in number of entries)
298
- cacheCSS: 750, // CSS cache size, default: 500 (1000 in CI mode)
299
- cacheJS: 250 // JS cache size, default: 500 (1000 in CI mode)
298
+ cacheCSS: 750, // CSS cache size, default: 500
299
+ cacheJS: 250 // JS cache size, default: 500
300
300
  });
301
301
  ```
302
302
 
@@ -325,26 +325,10 @@ html-minifier-next --minify-css --minify-js input.html
325
325
  }
326
326
  ```
327
327
 
328
- **For batch/CI processing:**
329
-
330
- Set `CI=true` to double default cache sizes (optimal for processing many files):
331
-
332
- ```shell
333
- # Single command
334
- CI=true html-minifier-next --minify-css --minify-js input.html
335
-
336
- # Or export for multiple commands
337
- export CI=true
338
- html-minifier-next --minify-css --minify-js file1.html
339
- html-minifier-next --minify-css --minify-js file2.html
340
- ```
341
-
342
- This is particularly useful in CI/CD pipelines where you’re processing multiple files and want better performance without manually tuning cache sizes.
343
-
344
328
  **When to adjust cache sizes:**
345
329
 
346
330
  * Single file processing: Default `500` is sufficient
347
- * Batch processing (CI/CD): Increase to `1000` or higher for better cache hit rates
331
+ * Batch processing: Increase to `1000` or higher for better cache hit rates
348
332
  * Memory-constrained environments: Reduce to `200`–`300` to save memory
349
333
  * Hundreds/thousands of files: Increase to `1000`–`2000` for optimal performance
350
334
 
@@ -383,6 +367,10 @@ What gets optimized:
383
367
  - `fill-opacity="1"` → removed
384
368
  - `stroke-linecap="butt"` → removed
385
369
 
370
+ 5. Leading and trailing zero removal: Unnecessary zeros are stripped from numeric values
371
+ - `0.5` → `.5`, `-0.3` → `-.3` (leading zeros)
372
+ - `1.0` → `1`, `10.500` → `10.5` (trailing zeros)
373
+
386
374
  You can customize the optimization behavior by providing an options object:
387
375
 
388
376
  ```javascript
package/cli.js CHANGED
@@ -6,9 +6,7 @@
6
6
  * The MIT License (MIT)
7
7
  *
8
8
  * Copyright 2014–2016 Zoltan Frombach
9
- *
10
9
  * Copyright Juriy “kangax” Zaytsev
11
- *
12
10
  * Copyright 2025 Jens Oliver Meiert
13
11
  *
14
12
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -283,8 +281,8 @@ program.option('--input-dir <dir>', 'Specify an input directory');
283
281
  program.option('--ignore-dir <patterns>', 'Exclude directories—relative to input directory—from processing (comma-separated), e.g., “libs” or “libs,vendor,node_modules”');
284
282
  program.option('--output-dir <dir>', 'Specify an output directory');
285
283
  program.option('--file-ext <extensions>', 'Specify file extension(s) to process (comma-separated), e.g., “html” or “html,htm,php”');
286
- program.option('--cache-css <size>', 'Set CSS minification cache size (number of entries, default: 500 [1000 in CI])', parseValidInt('cacheCSS'));
287
- program.option('--cache-js <size>', 'Set JavaScript minification cache size (number of entries, default: 500 [1000 in CI])', parseValidInt('cacheJS'));
284
+ program.option('--cache-css <size>', 'Set CSS minification cache size (number of entries, default: 500)', parseValidInt('cacheCSS'));
285
+ program.option('--cache-js <size>', 'Set JavaScript minification cache size (number of entries, default: 500)', parseValidInt('cacheJS'));
288
286
 
289
287
  (async () => {
290
288
  let content;
@@ -3145,7 +3145,7 @@ function mergeConsecutiveScripts(html) {
3145
3145
  * - Cache size is locked after first call—subsequent calls reuse the same cache
3146
3146
  * - Explicit `0` values are coerced to `1` (minimum functional cache size)
3147
3147
  *
3148
- * Default: `500` (or `1000` when `CI=true` environment variable is set)
3148
+ * Default: `500`
3149
3149
  *
3150
3150
  * @prop {number} [cacheJS]
3151
3151
  * The maximum number of entries for the JavaScript minification cache. Higher
@@ -3154,7 +3154,7 @@ function mergeConsecutiveScripts(html) {
3154
3154
  * - Cache size is locked after first call—subsequent calls reuse the same cache
3155
3155
  * - Explicit `0` values are coerced to `1` (minimum functional cache size)
3156
3156
  *
3157
- * Default: `500` (or `1000` when `CI=true` environment variable is set)
3157
+ * Default: `500`
3158
3158
  *
3159
3159
  * @prop {boolean} [caseSensitive]
3160
3160
  * When true, tag and attribute names are treated as case-sensitive.
@@ -4427,8 +4427,7 @@ function joinResultSegments(results, options, restoreCustom, restoreIgnore) {
4427
4427
  function initCaches(options) {
4428
4428
  // Only create caches once (on first call)—sizes are locked after this
4429
4429
  if (!cssMinifyCache) {
4430
- // Determine default size based on environment
4431
- const defaultSize = process.env.CI === 'true' ? 1000 : 500;
4430
+ const defaultSize = 500;
4432
4431
 
4433
4432
  // Helper to parse env var—returns parsed number (including 0) or undefined if absent, invalid, or negative
4434
4433
  const parseEnvCacheSize = (envVar) => {