[whatwg] HTML syntax: comments before doctype and doctype sniffing

On 18/06/07, Ian Hickson <ian at hixie.ch> wrote:
> On Sun, 3 Dec 2006, Simon Pieters wrote:
> > Also, as an additional constraint in the syntax section, the entire
> > doctype probably should (or must) be within the first 1024 bytes,
> > because AFAIK browsers generally only sniff for the first 1024 bytes,
> > and if they don't find the entire doctype within that then you get
> > quirks mode.
>
> I couldn't reproduce that.

In Firefox 2:

javascript:s='<?>';for(i=0;i<1006;++i)s+='
';window.location='data:text/html,'+s+'<!doctype
html><script>document.write(document.compatMode)</script>'

javascript:s='<?>';for(i=0;i<1007;++i)s+='
';window.location='data:text/html,'+s+'<!doctype
html><script>document.write(document.compatMode)</script>'

The first produces CSS1Compat, the second BackCompat. As far as I can
tell, Firefox requires the doctype to be found when parsing [using
standards-mode rules] the first 1024 characters (not bytes) from the
first non-whitespace character, and then it reparses the whole
document in quirks mode if necessary.

-- 
Philip Taylor
excors at gmail.com

Received on Monday, 18 June 2007 14:00:31 UTC