html-minifier-next 4.7.1 → 4.8.2
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 +19 -19
- package/cli.js +4 -3
- package/dist/htmlminifier.cjs +1884 -1660
- package/dist/htmlminifier.esm.bundle.js +33820 -33531
- package/dist/types/htmlminifier.d.ts +29 -3
- package/dist/types/htmlminifier.d.ts.map +1 -1
- package/dist/types/htmlparser.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/htmlminifier.js +1877 -1662
- package/src/htmlparser.js +10 -1
package/src/htmlparser.js
CHANGED
|
@@ -76,6 +76,14 @@ const nonPhrasing = new CaseInsensitiveSet(['address', 'article', 'aside', 'base
|
|
|
76
76
|
|
|
77
77
|
const reCache = {};
|
|
78
78
|
|
|
79
|
+
// Pre-compiled regexes for common special elements (`script`, `style`, `noscript`)
|
|
80
|
+
// These are used frequently and pre-compiling them avoids regex creation overhead
|
|
81
|
+
const preCompiledStackedTags = {
|
|
82
|
+
'script': /([\s\S]*?)<\/script[^>]*>/i,
|
|
83
|
+
'style': /([\s\S]*?)<\/style[^>]*>/i,
|
|
84
|
+
'noscript': /([\s\S]*?)<\/noscript[^>]*>/i
|
|
85
|
+
};
|
|
86
|
+
|
|
79
87
|
function attrForHandler(handler) {
|
|
80
88
|
let pattern = singleAttrIdentifier.source +
|
|
81
89
|
'(?:\\s*(' + joinSingleAttrAssigns(handler) + ')' +
|
|
@@ -224,7 +232,8 @@ export class HTMLParser {
|
|
|
224
232
|
prevTag = '';
|
|
225
233
|
} else {
|
|
226
234
|
const stackedTag = lastTag.toLowerCase();
|
|
227
|
-
|
|
235
|
+
// Use pre-compiled regex for common tags (`script`, `style`, `noscript`) to avoid regex creation overhead
|
|
236
|
+
const reStackedTag = preCompiledStackedTags[stackedTag] || reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)</' + stackedTag + '[^>]*>', 'i'));
|
|
228
237
|
|
|
229
238
|
html = await replaceAsync(html, reStackedTag, async (_, text) => {
|
|
230
239
|
if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
|