html-minifier-next 8.4.5 → 8.5.0

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/README.md CHANGED
@@ -108,7 +108,7 @@ HTML Minifier Next provides presets for common use cases. Presets are pre-config
108
108
  * `conservative`: Basic minification with whitespace collapsing, comment removal, and removal of select attributes.
109
109
  * `comprehensive`: More advanced minification for better file size reduction, including relevant conservative options plus attribute quote removal, optional tag removal, and more.
110
110
 
111
- 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.
111
+ 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. For output served with Gzip or Brotli, see [“Optimizing for compression”](#optimizing-for-compression) for what to add.
112
112
 
113
113
  **Using presets:**
114
114
 
@@ -172,7 +172,7 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
172
172
  | `removeComments`<br>`--remove-comments` | [Strip HTML comments](https://perfectionkills.com/experimenting-with-html-minifier/#remove_comments) | `false` |
173
173
  | `removeDefaultTypeAttributes`<br>`--remove-default-type-attributes` | Remove default `type` attributes from `style`/`link` (e.g., `type="text/css"`) and `script` (e.g., `type="text/javascript"`) elements; other `type` attribute values are left intact | `false` |
174
174
  | `removeEmptyAttributes`<br>`--remove-empty-attributes` | [Remove all attributes with whitespace-only values](https://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes) | `false` (could be `true`, `Function(attrName, tag)`) |
175
- | `removeEmptyElements`<br>`--remove-empty-elements` | [Remove all elements with empty contents](https://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements) | `false` |
175
+ | `removeEmptyElements`<br>`--remove-empty-elements` | [Remove all elements with empty contents](#removing-empty-elements) | `false` |
176
176
  | `removeEmptyElementsExcept`<br>`--remove-empty-elements-except` | Array of elements to preserve—use with `removeEmptyElements`; accepts simple tag names (e.g., `["td"]`) or HTML-like markup with attributes (e.g., `["<span aria-hidden='true'>"]`); supports double quotes, single quotes, and unquoted attribute values | `[]` |
177
177
  | `removeOptionalTags`<br>`--remove-optional-tags` | [Remove optional tags](https://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags) | `false` |
178
178
  | `removeRedundantAttributes`<br>`--remove-redundant-attributes` | [Remove attributes when value matches default](https://meiert.com/blog/optional-html/#toc-attribute-values) | `false` |
@@ -191,6 +191,9 @@ A few options take functions and are therefore only available programmatically,
191
191
  | Option | Description | Default |
192
192
  | --- | --- | --- |
193
193
  | `canCollapseWhitespace` | `Function(tag, attrs, defaultFn)` that determines whether whitespace inside an element can be collapsed—override to protect additional elements, delegating to `defaultFn` for the rest | Built-in handling (protects `pre`, `textarea`, etc.) |
194
+ | `canMinifyCSS` | Synchronous `Function(text, type)` that determines whether `minifyCSS` may process a given piece of CSS—returning `false` [leaves it as if `minifyCSS` were off](#css-minification) | All CSS is minified |
195
+ | `canMinifyJS` | Synchronous `Function(text, inline)` that determines whether `minifyJS` may process a given piece of JavaScript—returning `false` [leaves it unminified](#javascript-minification) | All JavaScript is minified |
196
+ | `canMinifySVG` | Synchronous `Function(text)` that determines whether `minifySVG` may pass a given outermost `svg` element to SVGO—returning `false` [skips SVGO for it](#svg-minification) | All SVG is minified |
194
197
  | `canTrimWhitespace` | `Function(tag, attrs, defaultFn)` that determines whether leading and trailing whitespace around an element may be trimmed | Built-in handling |
195
198
  | `log` | `Function(message)` called with warnings and errors, including minification errors swallowed by `continueOnMinifyError` (e.g., pass `console.error` to surface them); the CLI wires this up under `--verbose` and `--dry` | No-op (errors are silent) |
196
199
 
@@ -204,6 +207,9 @@ HTML Minifier Next: Ignoring `conservativeCollapse`—use with `collapseWhitespa
204
207
 
205
208
  | Option | Needs |
206
209
  | --- | --- |
210
+ | `canMinifyCSS` | `minifyCSS`, and not [a function of your own](#css-minification) |
211
+ | `canMinifyJS` | `minifyJS`, and not [a function of your own](#javascript-minification) |
212
+ | `canMinifySVG` | `minifySVG`, and not [a function of your own](#svg-minification) |
207
213
  | `collapseInlineTagWhitespace` | `collapseWhitespace` |
208
214
  | `conservativeCollapse` | `collapseWhitespace` |
209
215
  | `customEventAttributes` | `minifyJS` |
@@ -243,7 +249,44 @@ Where the modifiers disagree, the preserving one wins—`conservativeCollapse` a
243
249
 
244
250
  ### Sorting attributes and style classes
245
251
 
246
- Minifier options like `sortAttributes` and `sortClassNames` won’t impact the plain-text size of the output. However, `sortAttributes` (but not `sortClassNames`) improves the compression ratio for Gzip and Brotli used over HTTP.
252
+ `sortAttributes` and `sortClassNames` reorder attributes and class names by frequency, so that repeated markup looks more alike. This doesn’t change the plain-text size of the output, only how well it compresses: `sortAttributes` makes Gzip and Brotli output slightly smaller on average, though not on every page (see [“Optimizing for compression”](#optimizing-for-compression)); `sortClassNames` doesn’t help, and alongside `sortAttributes` cancels most of its gain with Brotli.
253
+
254
+ ### Optimizing for compression
255
+
256
+ Most HTML is served compressed, so the Gzip or Brotli size is often what counts—and it doesn’t always follow the raw size. Added to the `comprehensive` preset, these options changed output size as follows (average per page, relative to `comprehensive`):
257
+
258
+ | Added to `comprehensive` | Raw | Gzip (level 6) | Brotli (quality 6) | Brotli (quality 11) |
259
+ | --- | --- | --- | --- | --- |
260
+ | `sortAttributes` | ±0% | −0.20% | −0.21% | −0.16% |
261
+ | `sortAttributes`, `removeAttributeQuotes: false`, `quoteCharacter: '"'` | +1.75% | +0.08% | −0.15% | −0.39% |
262
+ | `removeEmptyElements` | −1.15% | −0.75% | −0.68% | −0.63% |
263
+
264
+ * **Gzip or on-the-fly Brotli:** Add `sortAttributes`. The gain is small and uneven, however, and sorting can double minification time for very large documents.
265
+ * **Brotli precompressed at quality 11** (as for static files compressed at build time): Add `sortAttributes`, don’t remove attribute quotes, and make the quotes double quotes. Raw and Gzip output grow, so this only pays off when clients receive the precompressed Brotli files.
266
+ * **`removeEmptyElements`** saves more than either, but may change the respective document—see [“Removing empty elements”](#removing-empty-elements) before enabling it.
267
+
268
+ ```shell
269
+ # Gzip or on-the-fly Brotli
270
+ npx html-minifier-next --preset comprehensive --sort-attributes input.html
271
+
272
+ # Brotli precompressed at quality 11
273
+ npx html-minifier-next --preset comprehensive --sort-attributes --no-remove-attribute-quotes --quote-character='"' input.html
274
+ ```
275
+
276
+ These figures were measured in September 2026 with HMN 8.4.5 on 31 pages of the [backtest corpus](#regression-tests) (retrieved February 2026). They are indications, not guarantees, as they depend on the markup and will shift as HMN and the minifiers it bundles change. The [benchmark](#working-tree-benchmarks) reports Gzip and Brotli (quality 6) sizes to re-check them.
277
+
278
+ ### Removing empty elements
279
+
280
+ `removeEmptyElements` removes elements without content—no text and no child elements (comments don’t count; whitespace does, unless `collapseWhitespace` removes it). It keeps:
281
+
282
+ * elements with an `id` attribute,
283
+ * `textarea` elements,
284
+ * `audio`, `video`, and `script` elements with a `src` attribute, `iframe` elements with `src` or `srcdoc`, `object` elements with `data`, and `applet` elements with `code`,
285
+ * elements inside SVG and MathML—though an empty `svg` or `math` element itself is removed, and HTML inside them (as in `foreignObject` or `annotation-xml`) is still processed.
286
+
287
+ Everything else goes, including elements that are empty on purpose: icons as well as icon links and buttons styled with CSS (e.g., `<i class="icon"></i>` or `<button aria-label="Close"></button>`), `canvas` elements that scripts draw into, empty `option` elements, and empty table cells (which shifts the cells that follow). Keep such elements with `removeEmptyElementsExcept`, for example `["td", "canvas", "<button aria-label>"]`. A parent that is left empty by the removal is kept.
288
+
289
+ Where the markup allows it, the option is effective: On a test corpus, it reduced output by 1.15% raw and 0.75% with Gzip on average (see [“Optimizing for compression”](#optimizing-for-compression)).
247
290
 
248
291
  ### CSS minification
249
292
 
@@ -284,9 +327,18 @@ const result = await minify(html, {
284
327
  });
285
328
  ```
286
329
 
330
+ To exempt individual pieces of CSS, pass `canMinifyCSS` a synchronous function. It receives the CSS and its type—`undefined` for `style` elements, `'inline'` for `style` attributes, and `'media'` for `media` attributes. CSS for which it returns `false` comes out as if `minifyCSS` were off, so its URLs are not minified and its unused rules not removed, either. (Within `svg` elements, `minifySVG` has SVGO minify CSS as well—exempt those with [`canMinifySVG`](#svg-minification).)
331
+
332
+ ```js
333
+ const result = await minify(html, {
334
+ minifyCSS: true,
335
+ canMinifyCSS: text => !text.includes('/* keep */')
336
+ });
337
+ ```
338
+
287
339
  ### Unused CSS removal
288
340
 
289
- `removeUnusedCSS` removes rules from `style` elements whose class or ID selectors the document doesn’t reference. It needs to be used with `minifyCSS`, because the removal runs through Lightning CSS—passing `minifyCSS` a function of your own replaces that step, so the removal does not apply, either. Both cases are reported through [the `log` hook](#api-only-options). It does not touch `style` or `media` attributes.
341
+ `removeUnusedCSS` removes rules from `style` elements whose class or ID selectors a document doesn’t reference. It needs to be used with `minifyCSS`, because the removal runs through Lightning CSS—passing `minifyCSS` a function of your own replaces that step, so the removal does not apply, either. Both cases are reported through [the `log` hook](#api-only-options). It does not touch `style` or `media` attributes.
290
342
 
291
343
  ```js
292
344
  const result = await minify(html, {
@@ -384,6 +436,15 @@ const result = await minify(html, {
384
436
  });
385
437
  ```
386
438
 
439
+ To exempt individual pieces of JavaScript, pass `canMinifyJS` a synchronous function. It receives the JavaScript and whether it is inline—`true` for event handler attributes (e.g., `onclick`), `false` for `script` elements. JavaScript for which it returns `false` is left unminified, though `mergeScripts` still merges it with adjacent scripts:
440
+
441
+ ```js
442
+ const result = await minify(html, {
443
+ minifyJS: true,
444
+ canMinifyJS: text => !text.includes('/* keep */')
445
+ });
446
+ ```
447
+
387
448
  ### SVG minification
388
449
 
389
450
  When `minifySVG` is set to `true`, HTML Minifier Next uses [SVGO](https://svgo.dev/) to optimize inline SVG elements. Complete `<svg>` subtrees are extracted and processed as a block, enabling deep structural optimization:
@@ -420,6 +481,15 @@ const result = await minify(html, {
420
481
  });
421
482
  ```
422
483
 
484
+ To exempt individual `svg` elements, pass `canMinifySVG` a synchronous function. It receives each outermost `svg` element, including any `svg` elements nested in it, as the HTML pass wrote it (e.g., without comments under `removeComments`), and one for which it returns `false` skips SVGO. To keep an `svg` element exactly as written, [wrap it in `<!-- htmlmin:ignore -->`](#ignoring-chunks-of-markup) instead.
485
+
486
+ ```js
487
+ const result = await minify(html, {
488
+ minifySVG: true,
489
+ canMinifySVG: text => !text.includes('data-keep')
490
+ });
491
+ ```
492
+
423
493
  **Important:**
424
494
 
425
495
  * SVG minification only applies within `<svg>` elements
@@ -731,7 +801,7 @@ npm i;
731
801
  npm run backtest
732
802
  ```
733
803
 
734
- The backtest tool tracks minification performance across Git history. Results are saved in the backtest folder as a JSON file, results.json.
804
+ The backtest tool tracks minification performance—output size (raw, Gzip, and Brotli) and processing time—across Git history. Results are saved in the backtest folder (results.json).
735
805
 
736
806
  Parameters:
737
807
 
@@ -749,7 +819,7 @@ npm i;
749
819
  npm run benchmark
750
820
  ```
751
821
 
752
- It reuses the backtest corpus (run `npm run backtest` once to download it) and reports per-file output size and processing time.
822
+ It reuses the backtest corpus (run `npm run backtest` once to download it) and reports per-file output size and processing time. Sizes are given raw and compressed—at common defaults for on-the-fly compression, i.e., Gzip at level 6 and Brotli at quality 6—since a change that shrinks raw output can still grow what is transferred.
753
823
 
754
824
  Parameters:
755
825
 
@@ -758,7 +828,8 @@ Parameters:
758
828
  * `--core`: Disables the external minifiers (CSS, JS, SVG, URLs) to isolate HMN’s processing time
759
829
  * `--cold`: Switches the minification caches off so CSS, JS, and SVG work is redone on every iteration—without it, warm caches serve those results from memory after the warm-up run and the benchmark cannot see changes to those minifiers
760
830
  * `--iterations=N`: Sets the number of timed iterations (default: 5)
761
- * `--config=PATH`: Uses an alternative options file (default: html-minifier-next.config.json)
831
+ * `--config=PATH`: Uses an alternative options file (default: html-minifier-next.config.json); the file can name a `preset` to start from
832
+ * `--preset=NAME`: Uses a preset instead of an options file (e.g., `--preset=comprehensive`)
762
833
 
763
834
  To compare branches (A/B run), execute `npm run benchmark -- --save` on `main`, then `npm run benchmark` on the branch to see the deltas. Add `--core` on both ends when measuring changes to HMN rather than bundled minifiers, or `--cold` when measuring changes to the CSS, JS, or SVG minification paths.
764
835
 
@@ -15,6 +15,34 @@ export type MinifierOptions = {
15
15
  * Default: Built-in `canCollapseWhitespace` function
16
16
  */
17
17
  canCollapseWhitespace?: (tag: string, attrs: HTMLAttribute[], canCollapseWhitespace: (tag: string) => boolean) => boolean;
18
+ /**
19
+ * Synchronous predicate that determines whether the built-in `minifyCSS` may
20
+ * process a given piece of CSS—`type` is `undefined` for `style` elements,
21
+ * `'inline'` for `style` attributes, and `'media'` for `media` attributes.
22
+ * Returning false leaves that CSS as if `minifyCSS` were off, including its URLs
23
+ * and unused rules (within `svg` elements, SVGO still minifies it under `minifySVG`).
24
+ *
25
+ * Default: `null` (all CSS is minified)
26
+ */
27
+ canMinifyCSS?: ((text: string, type?: 'inline' | 'media') => boolean) | null;
28
+ /**
29
+ * Synchronous predicate that determines whether the built-in `minifyJS` may
30
+ * process a given piece of JavaScript—`inline` is true for event handler
31
+ * attributes. Returning false leaves that JavaScript unminified (`mergeScripts`
32
+ * still applies).
33
+ *
34
+ * Default: `null` (all JavaScript is minified)
35
+ */
36
+ canMinifyJS?: ((text: string, inline?: boolean) => boolean) | null;
37
+ /**
38
+ * Synchronous predicate that determines whether the built-in `minifySVG` may
39
+ * pass a given outermost `svg` element, nested ones included, to SVGO. It
40
+ * receives the element as serialized by the HTML pass (e.g., without comments
41
+ * under `removeComments`); returning false leaves it as that pass wrote it.
42
+ *
43
+ * Default: `null` (all SVG is minified)
44
+ */
45
+ canMinifySVG?: ((text: string) => boolean) | null;
18
46
  /**
19
47
  * Predicate that determines whether leading/trailing whitespace around
20
48
  * the element may be trimmed.
@@ -1 +1 @@
1
- {"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAwE/D,YAAkB,aAAa,GAI/B;IAAe,IAAI,EAAZ,MAAM,CACb;IAAgB,KAAK,AAArB,CACA,EADO,MAAM,CACb;IAAgB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AAM,KAAK,MAAM,CAAC,CAQ5C;;;;;;;;IAAiB,mBAAmB,AAApC,CAOA,EAPO,OAAO,CAOd;;;;;;;IAAiB,eAAe,AAAhC,CAKF,EALS,OAAO,CAKhB;CAAA,CAAA;AA0EE,YAAkB,UAAU,GAG5B;;;;IAAe,IAAI,EAAZ,MAAM,CACb;;;;IAAe,IAAI,EAAZ,MAAM,CACb;;;;IAAe,IAAI,EAAZ,MAAM,CACb;;;;IAAe,KAAK,EAAb,MAAM,CACf;CAAA,CAAA;AAwgDD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAFhB;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,CAQhE;AA2FD;;;;GAIG;AACH,eAAO,MAAM,MAAM,UAJR,MAAM,YACN,eAAe,KACb,OAAO,CAAC,MAAM,CAsE1B,CAAC;AAIF,OAAO,EACL,OAAO,EACP,SAAS,EACT,cAAc,EACf,CAAC"}
@@ -21,6 +21,9 @@ export type ProcessedOptions = Omit<MinifierOptions, 'preset' | 'canCollapseWhit
21
21
  minifyJS: (text: string, inline?: boolean, isModule?: boolean) => string | Promise<string>;
22
22
  minifyURLs: (text: string) => string | Promise<string>;
23
23
  minifySVG: ((svgContent: string) => string | Promise<string>) | null;
24
+ canMinifyCSS: ((text: string, type?: 'inline' | 'media') => boolean) | null;
25
+ canMinifyJS: ((text: string, inline?: boolean) => boolean) | null;
26
+ canMinifySVG: ((text: string) => boolean) | null;
24
27
  removeUnusedCSS: {
25
28
  safelist: Array<string | RegExp>;
26
29
  scripts: boolean;
@@ -64,6 +67,9 @@ export type ProcessedOptions = Omit<MinifierOptions, 'preset' | 'canCollapseWhit
64
67
  * minifyJS: (text: string, inline?: boolean, isModule?: boolean) => string | Promise<string>,
65
68
  * minifyURLs: (text: string) => string | Promise<string>,
66
69
  * minifySVG: ((svgContent: string) => string | Promise<string>) | null,
70
+ * canMinifyCSS: ((text: string, type?: 'inline' | 'media') => boolean) | null,
71
+ * canMinifyJS: ((text: string, inline?: boolean) => boolean) | null,
72
+ * canMinifySVG: ((text: string) => boolean) | null,
67
73
  * removeUnusedCSS: {safelist: Array<string | RegExp>, scripts: boolean} | null,
68
74
  * cssContext?: CSSContext,
69
75
  * parallelJS?: boolean,
@@ -76,6 +82,7 @@ export type ProcessedOptions = Omit<MinifierOptions, 'preset' | 'canCollapseWhit
76
82
  */
77
83
  /** @param {ProcessedOptions} options */
78
84
  declare function shouldMinifyInnerHTML(options: ProcessedOptions): boolean;
85
+ declare const optionKeysExtra: Set<string>;
79
86
  export type OptionDependency = OptionDependency[];
80
87
  /**
81
88
  * Options that do nothing on their own, and the option each one needs to take effect
@@ -94,13 +101,13 @@ export type OptionDependency = OptionDependency[];
94
101
  declare const optionDependencies: ({
95
102
  option: string;
96
103
  requires: string;
104
+ unusable: (input: Record<string, any>) => "which a function of your own replaces" | false;
105
+ clear: boolean;
106
+ } | {
97
107
  unusable?: never;
98
108
  clear?: never;
99
- } | {
100
109
  option: string;
101
110
  requires: string;
102
- unusable: (/** @type {Record<string, any>} */ input: Record<string, any>) => "which a function of your own replaces" | false;
103
- clear: boolean;
104
111
  })[];
105
112
  /**
106
113
  * @param {MinifierOptions} inputOptions - User-provided options
@@ -116,5 +123,5 @@ declare const processOptions: (inputOptions: MinifierOptions, { getLightningCSS,
116
123
  jsMinifyCache?: LRU | undefined;
117
124
  svgMinifyCache?: LRU | undefined;
118
125
  }) => ProcessedOptions;
119
- export { optionDependencies, shouldMinifyInnerHTML, processOptions };
126
+ export { optionDependencies, optionKeysExtra, shouldMinifyInnerHTML, processOptions };
120
127
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/lib/options.js"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,GAAG,EAAmJ,MAAM,YAAY,CAAC;AAQ9K,OAAQ,KAAA,EAAE,e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,KAAK,MAAM,CAAC;IACtC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAkB;AA/CtB,2EAA2E;AAI3E;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,wCAAwC;AACxC,iBAAS,qBAAqB,CAAC,OAAO,EAD1B,gBAC0B,WAUrC;AA0BD,QAAA,MAAM,eAAe,aAA0H,CAAC;AAyB7I,YAAkB,gBAAgB,GAM3B,gBAAgB,EAAE,CAAC;AAZ7B;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,kBAAkB;;;sBAhBV,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;;;IAmChC,CAAC;AAmEF;;;;GAIG;AACH,QAAA,MAAM,cAAc,iBAJT,eAAe,mGACf;IAAC,eAAe,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IAAC,aAAa,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,GAAG,GAAG,SAAS,CAAA;CAAC,KAC5O,gBAukBZ,CAAC;AAIF,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACf,CAAC"}
package/package.json CHANGED
@@ -89,11 +89,11 @@
89
89
  "prepack": "npm run build",
90
90
  "prepare": "git config core.hooksPath .githooks || true",
91
91
  "serve": "vite",
92
- "test": "npm run test:types && node --test \"test/**/*.test.js\"",
92
+ "test": "npm run test:types && node --test \"test/**/*.test.js\" \"backtest/*.test.js\"",
93
93
  "test:types": "tsc --noEmit && tsc --project tsconfig.test.json",
94
- "test:watch": "node --test --watch \"test/**/*.test.js\""
94
+ "test:watch": "node --test --watch \"test/**/*.test.js\" \"backtest/*.test.js\""
95
95
  },
96
96
  "type": "module",
97
97
  "types": "dist/types/htmlminifier.d.ts",
98
- "version": "8.4.5"
98
+ "version": "8.5.0"
99
99
  }
@@ -95,6 +95,31 @@ import { toFragment, replaceCustomFragments } from './lib/fragments.js';
95
95
  *
96
96
  * Default: Built-in `canCollapseWhitespace` function
97
97
  *
98
+ * @prop {((text: string, type?: 'inline' | 'media') => boolean) | null} [canMinifyCSS]
99
+ * Synchronous predicate that determines whether the built-in `minifyCSS` may
100
+ * process a given piece of CSS—`type` is `undefined` for `style` elements,
101
+ * `'inline'` for `style` attributes, and `'media'` for `media` attributes.
102
+ * Returning false leaves that CSS as if `minifyCSS` were off, including its URLs
103
+ * and unused rules (within `svg` elements, SVGO still minifies it under `minifySVG`).
104
+ *
105
+ * Default: `null` (all CSS is minified)
106
+ *
107
+ * @prop {((text: string, inline?: boolean) => boolean) | null} [canMinifyJS]
108
+ * Synchronous predicate that determines whether the built-in `minifyJS` may
109
+ * process a given piece of JavaScript—`inline` is true for event handler
110
+ * attributes. Returning false leaves that JavaScript unminified (`mergeScripts`
111
+ * still applies).
112
+ *
113
+ * Default: `null` (all JavaScript is minified)
114
+ *
115
+ * @prop {((text: string) => boolean) | null} [canMinifySVG]
116
+ * Synchronous predicate that determines whether the built-in `minifySVG` may
117
+ * pass a given outermost `svg` element, nested ones included, to SVGO. It
118
+ * receives the element as serialized by the HTML pass (e.g., without comments
119
+ * under `removeComments`); returning false leaves it as that pass wrote it.
120
+ *
121
+ * Default: `null` (all SVG is minified)
122
+ *
98
123
  * @prop {(tag: string | null, attrs: HTMLAttribute[] | undefined, canTrimWhitespace: (tag: string) => boolean) => boolean} [canTrimWhitespace]
99
124
  * Predicate that determines whether leading/trailing whitespace around
100
125
  * the element may be trimmed.
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { createUrlMinifier } from './urls.js';
6
- import { LRU, MAX_CACHE_ENTRY_SIZE, stableStringify, hashContent, identity, lowercase, paramCase, replaceAsync, parseRegExp, describeQuantifierRisk, lostFlag } from './utils.js';
6
+ import { LRU, MAX_CACHE_ENTRY_SIZE, stableStringify, hashContent, identity, isThenable, lowercase, paramCase, replaceAsync, parseRegExp, describeQuantifierRisk, lostFlag } from './utils.js';
7
7
  import { RE_TRAILING_SEMICOLON, MISSING_DEPENDENCY, svgoPluginsInline } from './constants.js';
8
8
  import { canCollapseWhitespace, canTrimWhitespace } from './whitespace.js';
9
9
  import { wrapCSS, unwrapCSS } from './content.js';
@@ -47,6 +47,9 @@ import { optionDefinitions, optionDefaults } from './option-definitions.js';
47
47
  * minifyJS: (text: string, inline?: boolean, isModule?: boolean) => string | Promise<string>,
48
48
  * minifyURLs: (text: string) => string | Promise<string>,
49
49
  * minifySVG: ((svgContent: string) => string | Promise<string>) | null,
50
+ * canMinifyCSS: ((text: string, type?: 'inline' | 'media') => boolean) | null,
51
+ * canMinifyJS: ((text: string, inline?: boolean) => boolean) | null,
52
+ * canMinifySVG: ((text: string) => boolean) | null,
50
53
  * removeUnusedCSS: {safelist: Array<string | RegExp>, scripts: boolean} | null,
51
54
  * cssContext?: CSSContext,
52
55
  * parallelJS?: boolean,
@@ -97,7 +100,7 @@ function getUrlMinifyCache(site) {
97
100
  }
98
101
 
99
102
  // User-facing option keys that are valid but not listed in `optionDefinitions`
100
- const optionKeysExtra = new Set(['preset', 'log', 'canCollapseWhitespace', 'canTrimWhitespace']);
103
+ const optionKeysExtra = new Set(['preset', 'log', 'canCollapseWhitespace', 'canTrimWhitespace', 'canMinifyCSS', 'canMinifyJS', 'canMinifySVG']);
101
104
 
102
105
  // Unknown option keys and preset names already warned about—warn once per
103
106
  // key per process, so repeated `minify` calls (e.g., batch runs) don’t flood STDERR
@@ -112,6 +115,10 @@ const unusedCSSWarned = new Set();
112
115
  // Object-valued options handed a string, warned about once per distinct value
113
116
  const stringValuesWarned = new Set();
114
117
 
118
+ // Clause for options that only the built-in minifier behind `key` reads
119
+ const replacedByOwnFunction = (/** @type {string} */ key) =>
120
+ (/** @type {Record<string, any>} */ input) => typeof input[key] === 'function' && 'which a function of your own replaces';
121
+
115
122
  /**
116
123
  * Options that do nothing on their own, and the option each one needs to take effect
117
124
  *
@@ -127,6 +134,9 @@ const stringValuesWarned = new Set();
127
134
  * @type {OptionDependency[]}
128
135
  */
129
136
  const optionDependencies = [
137
+ { option: 'canMinifyCSS', requires: 'minifyCSS', unusable: replacedByOwnFunction('minifyCSS'), clear: true },
138
+ { option: 'canMinifyJS', requires: 'minifyJS', unusable: replacedByOwnFunction('minifyJS'), clear: true },
139
+ { option: 'canMinifySVG', requires: 'minifySVG', unusable: replacedByOwnFunction('minifySVG'), clear: true },
130
140
  { option: 'collapseInlineTagWhitespace', requires: 'collapseWhitespace' },
131
141
  { option: 'conservativeCollapse', requires: 'collapseWhitespace' },
132
142
  { option: 'customEventAttributes', requires: 'minifyJS' },
@@ -138,7 +148,7 @@ const optionDependencies = [
138
148
  option: 'removeUnusedCSS',
139
149
  requires: 'minifyCSS',
140
150
  // Removal rides along with Lightning CSS, which a function of one’s own replaces
141
- unusable: (/** @type {Record<string, any>} */ input) => typeof input.minifyCSS === 'function' && 'which a function of your own replaces',
151
+ unusable: replacedByOwnFunction('minifyCSS'),
142
152
  clear: true
143
153
  },
144
154
  { option: 'trimCustomFragments', requires: 'collapseWhitespace' }
@@ -152,6 +162,34 @@ function isRequested(value) {
152
162
  return Array.isArray(value) ? value.length > 0 : Boolean(value);
153
163
  }
154
164
 
165
+ // A `canMinify…` hook that returns false leaves the content as is, as does one that
166
+ // throws under `continueOnMinifyError`; hooks are synchronous, so a promise counts as an error
167
+ /**
168
+ * @param {ProcessedOptions} options - Processed options
169
+ * @param {'canMinifyCSS' | 'canMinifyJS' | 'canMinifySVG'} name - Hook to consult
170
+ * @param {...any} args - Arguments for the hook
171
+ * @returns {boolean}
172
+ */
173
+ function declinesMinify(options, name, ...args) {
174
+ const hook = /** @type {((...args: any[]) => unknown) | null} */ (options[name]);
175
+ if (!hook) return false;
176
+ try {
177
+ const result = hook(...args);
178
+ if (isThenable(result)) {
179
+ // Keep a later rejection from surfacing as unhandled
180
+ /** @type {Promise<unknown>} */ (result).catch(() => {});
181
+ throw new TypeError(`\`${name}\` must return a boolean, not a promise`);
182
+ }
183
+ return !result;
184
+ } catch (err) {
185
+ if (!options.continueOnMinifyError) {
186
+ throw err;
187
+ }
188
+ options.log && options.log(err);
189
+ return true;
190
+ }
191
+ }
192
+
155
193
  /** @param {unknown} err - Error raised while minifying */
156
194
  function isMissingDependency(err) {
157
195
  return Boolean(err) && /** @type {any} */ (err).code === MISSING_DEPENDENCY;
@@ -198,6 +236,9 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
198
236
  minifyJS: identity,
199
237
  minifyURLs: identity,
200
238
  minifySVG: null,
239
+ canMinifyCSS: null,
240
+ canMinifyJS: null,
241
+ canMinifySVG: null,
201
242
  removeUnusedCSS: null
202
243
  };
203
244
 
@@ -291,6 +332,10 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
291
332
  if (typeof option === 'function') {
292
333
  options.log = option;
293
334
  }
335
+ } else if (key === 'canMinifyCSS' || key === 'canMinifyJS' || key === 'canMinifySVG') {
336
+ if (typeof option === 'function') {
337
+ optionsDynamic[key] = option;
338
+ }
294
339
  } else if (key === 'minifyCSS' && typeof option !== 'function') {
295
340
  if (!option || !getLightningCSS || !cssMinifyCache) {
296
341
  return;
@@ -307,6 +352,10 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
307
352
  return text;
308
353
  }
309
354
 
355
+ if (declinesMinify(options, 'canMinifyCSS', text, type)) {
356
+ return text;
357
+ }
358
+
310
359
  // Warnings are stored with the minified result and replayed on every hit, so a
311
360
  // second document with the same defect hears about it, too; `context.warned`
312
361
  // then keeps one document from repeating itself. Reporting from the cache
@@ -501,6 +550,10 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
501
550
  return '';
502
551
  }
503
552
 
553
+ if (declinesMinify(options, 'canMinifyJS', text, inline)) {
554
+ return text;
555
+ }
556
+
504
557
  // Hybrid strategy: Always use Terser for inline JS (needs bare returns support)
505
558
  // Use user’s chosen engine for script blocks
506
559
  const useEngine = inline ? 'terser' : engine;
@@ -639,6 +692,10 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
639
692
  return svgContent;
640
693
  }
641
694
 
695
+ if (declinesMinify(options, 'canMinifySVG', svgContent)) {
696
+ return svgContent;
697
+ }
698
+
642
699
  const isCacheable = svgContent.length <= MAX_CACHE_ENTRY_SIZE;
643
700
  const svgKey = isCacheable
644
701
  ? (svgContent.length > 2048
@@ -754,6 +811,7 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
754
811
 
755
812
  export {
756
813
  optionDependencies,
814
+ optionKeysExtra,
757
815
  shouldMinifyInnerHTML,
758
816
  processOptions
759
817
  };