kangax / kangax/html-minifier

js + html fail if compress in one single line

Open
#1,148 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5k
Forks
577
PR merge metrics
No merged PRs in 30d

Description

Hello!

If the problem has already been pointed out, I apologize in advance.

I'll try to contribute anyway...

During a runtime minify requests I realized that html and js together failed, I investigated a possible solution and noticed that, when the code is planed, it is first built leaving the js comments that return an error.

I solved it this way but, perhaps, the system should first remove the comments and then align the js code.

```js
const opts = {
minifyHTML: true,
minifyJS: true,
minifyCSS: true,
processScripts:true,
removeComments: true,
removeScriptTypeAttributes: true,
includeAutoGeneratedTags: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
removeStyleLinkTypeAttributes: true,
preserveLineBreaks:false,
collapseWhitespace: true,
continueOnParseError: true,
// ignoreCustomFragments: [/\n/]
}

minify( MyUTF8Output.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, ''), opts )
```

In this way the html+js output minify will be complete, compressed and in a single line

in other case need ```.replace(/(?|\`)>(\s*)<')``` for remove every newline between tags (exluded inner pre and preformatted ``)

I don't get why go into strange confict in my config.

I hope that this post can suggest something to someone.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with the shown HTML and JavaScript input and minify options. Inspect the combined HTML/JavaScript minification path around comment removal and JavaScript alignment; done means the input minifies without a parse error into the expected single-line output.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
tooling, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.