angularjshtmlgoogle-chromeamp-html

HTML Comments without DOCTYPE


I'm running into a config issue with a Angular/AMP setup that I'm trying to debug. I have a hunch on what the problem could be, but I'm having trouble verifying if some compilers might misunderstand a HTML comments without <!DOCTYPE html> present (which is an issue in itself).

To provide a simple overview of the page I'm working with, the site renders something like the below within the DOM on the none AMP page (note the lack of <!DOCTYPE html>).

<html>
<head>
  <!---->
    <link rel="amphtml" href="https://www.foo.com/amp/document.html">
  <!---->

</head>
  <body>
    <p>Foo site</p>
  </body>
</html>

The Angular template will check if the site is a valid AMP page and will return the AMP link if so, and will leave behind <!---->.

I realize that a valid HTML comment is something like <!-- foo -->, however could a compiler possibly interpret something like <!----><link rel="amphtml" ... ><!----> as a comment when <!DOCTYPE html> isn't present? Specifically, could Chrome 41 see this as a comment?

Viewing the AMP link within Chrome 63 everything looks valid, but I'd like to rule out this one hypothesis before continuing to dig in the problem.

Many thanks in advance and apologies for the silly question :)


Solution

  • It’s not clear what you mean by “compilers”, but as far as behavior of HTML parsers in browsers, I think you can rule out the case of any browser parser handling the comment in the markup snippet in the question any differently based on whether or not the document has a doctype.

    Per the parsing algorithm defined in the HTML spec, the lack of the doctype puts HTML parsers in quirks mode, and a number of “quirks” in parsing/rendering behavior occur — some documented at https://quirks.spec.whatwg.org/ and others documented in the DOM, CSSOM, and CSSOM View specs, in the HTML spec itself, and informally in places like What happens in Quirks Mode?

    But among none of those documented quirks is there any quirk related to parsing of comments.

    If such a quirk existed, it’d almost certainly be part of the parsing algorithm in the HTML spec itself.

    I guess it’s imaginable a parser which doesn’t conform to the parsing algorithm in the HTML spec might do something different with the markup snippet shown in the question — but as far as parsers in browsers, all modern browser versions for at least the last 6 years have implemented parsers that conform to the parsing algorithm in the HTML spec.

    Chrome, for example, has implemented a spec-conforming HTML parser since Chrome 7 (2010).

    So I think you can eliminate the possibility of that markup case is getting parsed differently by any browser engine based on whether or not the doctype is there.