Closed ernestosotelo closed 5 years ago
Dropping empty html, head and body tags is by design since they are nominally redundant, and Google encourages their removal in plain HTML5 for example, though various 'consumers' of of HTML (such as Bing, and AMP) don't like it.
@ernestosotelo from your description I cannot see why any of these won't work - even with any additional tags, the following JavaScript would get executed in all major web browsers:
<script>alert('Hello World!');</script>
Please provide a concrete example if you think html-minifier
is at fault here. And as you pointed out, it is entirely possible that this issue has nothing to do html-minifier
in the first place.
@alexlamsl Thanks for your response. I looked into it a bit more, and it seems that Visual Studio Code's live-server is the culprit. The page works perfectly fine when deployed, or when just opening the page locally without live-server. It seems, for whichever reason, that live-server does not respect opting out of these HTML tags. I definitely wasn't aware that omitting these tags was permissible for browsers. So, you definitely taught me a thing or two here.
Thanks folks, I will continue to use this package as this was my only minor issue :)
Respectfully,
Ernie
My site is not working after having minified it and loosing the html / head / body tags this way. The page loads a csv-file with papaparse and chart.js. I use HTMLMinifier with Sublime. Chart.js will not be able to create the chart without the html / head / body tag.
Is there an option to not remove the closing tags. I just want to have the html condensed but I like keep its structure intact.
Are you using --remove-optional-tags? Does omitting it do what you want?
My core safe set of flags is:
COREOPTS="--minify-css true --minify-js true \ --collapse-whitespace --conservative-collapse \ --collapse-boolean-attributes \ --no-include-auto-generated-tags \ --remove-attribute-quotes \ --remove-redundant-attributes \ --remove-comments --remove-empty-attributes \ --remove-script-type-attributes --remove-style-link-type-attributes \ --sort-class-name"
I am a bit more aggressive for ‘lite’ / m-dot pages and also use --remove-optional-tags for them.
Rgds
Damon
On 27 Jun 2020, at 11:07, Qian Chen notifications@github.com wrote:
Is there an option to not remove the closing tags. I just want to have the html condensed but I like keep its structure intact.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kangax/html-minifier/issues/1020#issuecomment-650535759, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAY5FYASQLNZIJGAJVWUFQTRYXAFFANCNFSM4HGDY4TQ.
Hi guys,
When I opened my website with live server I noticed none of my JS functionalities were working. I quickly glanced over the minified HTML file and found that the html closing tag and both body tags were missing in the minified version.
I am running html-minifier with node-minifier
"@node-minify/core": "^4.0.5", "@node-minify/cssnano": "^4.1.0", "@node-minify/html-minifier": "^4.0.5", "@node-minify/uglify-es": "^4.0.5",
All the other minifiers have ran successfully.
I have a simple node-minifier config with no error handling, etc.
If this is a node-minifier issue then I will have to address it there. Thanks in advance, and for your hard work folks.
Ernie