question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi all,

Trying in this tool : https://kangax.github.io/html-minifier/

I tried minimizing the source-code of that same page. The minimized code does not validate. Particularily, the <!DOCTYPE html> is reduced to <!doctypehtml>, which is not okay.

To reproduce:

  • Copy this minimal HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Page</title>
</head>
<body>
	<div class="mydiv">Stuff</div>
</body>
</html>
  • paste it on that same page
  • minify it
  • try to validate the minified code.

Result:

Minified code is

<!doctypehtml><html lang=en><meta charset=UTF-8><title>Page</title><div class=mydiv>Stuff</div>

Which is not valid:

Error: Missing space before doctype name. At line 1, column 10

Expectation:

Minified code should be valid, ie be atleast this:

<!doctype html><html lang=en><meta charset=UTF-8><title>Page</title><div class=mydiv>Stuff</div>

End notes

This is the only error on my minimal HTML code example. If you try minifying the HTML of the online tool itself, you’ll find another error, most similar.

Appart from that it seems to do the job. Thanks for that all!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:17

github_iconTop GitHub Comments

1reaction
j9tcommented, Oct 11, 2021

IMHO, validating minified HTML is like trying to lint minified JavaScript code — you’re validating the wrong thing! We should be validating the authored, unminified HTML, and then ideally trusting the HTML minifier to do its job.

I’d beg to differ (largely because of the current shape of frontend dev) but it’s an interesting conversation to be had. Probably not here though?

1reaction
XhmikosRcommented, Oct 11, 2021

Yeah, but it’s unsafe and we do have other unsafe options disabled by default. Disabling removeTagWhitespace on the website too brings things on par with the CLI 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML doctype declaration - W3Schools
All HTML documents must start with a <!DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser...
Read more >
: It's Code For Declaring A DOCTYPE In HTML5 »
All HTML need to have a DOCTYPE declared. The DOCTYPE is not actually an element or HTML tag. It lets the browser know...
Read more >
Doctype - MDN Web Docs Glossary: Definitions of ... - Mozilla
In HTML, the doctype is the required " <!DOCTYPE html> " preamble found at the top of all documents. Its sole purpose is...
Read more >
HTML: <!DOCTYPE> tag - TechOnTheNet
The HTML <!DOCTYPE> tag is the very first line in the HTML document. It tells the browser what version of HTML the document...
Read more >
Recommended list of Doctype declarations you can ... - W3C
Recommended Doctype Declarations to use in your Web document. ... When authoring document is HTML or XHTML, it is important to Add a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found