Re:Google HTML/CSS Style Guide – Omit Optional Tags
by Sidnicious on Saturday September 17, 2016 @04:24PM
(#12522272)
What's happening isn't what you think is happening.
The parser creates an empty head element when it sees the <body> start tag, the second <head> start tag is ignored, and the <script> is treated as part of the body element. Try changing the body of the <script> tag to this:
alert(document.currentScript.parentNode);
It alerts "[object HTMLBodyElement]".The behavior is specced out here, if you're curious: https://www.w3.org/TR/html5/syntax.html#parsing-main-afterbo...
This is why window.onload and then jQuery's document.ready, and later, putting the script at the end of your file, is a best practice.