Heads or Tails?
It started with the question why Google had abandoned the practice to just append scripts to the <head>-section of a document in order to dynamically load additional scripts in an asynchronous matter. For instance, Google Analytics now uses this technique for asynchronous loading:
1 2 3 4 5 6 7
The main problem with a simple approach such as just appending newly created scripts to the <head> (by using f.i. document.getElementsByTagName('head').appendChild()) is that some documents (and in some browsers) don't appear to have a <head> in the DOM.
I pointed out in the comments to Steve's blogpost that there may be more to it than just a browsers' failure to adhere to the applicable specifications, although Steve's testresults already showed that some specific browsers (and on some specific mobile platforms) that don't implicitly create a <head>-element in the DOM-tree make up a sufficient share such that relying on that is currently unwise.
However, Steve indirectly asked me to create my own browsertest in order to explore this issue further and to see if for instance quirksmode would make a difference. I already knew for a fact that a <head>-less document in true XHTML (served as application/xhtml+xml) would normally not have a <head>-section in the DOM (and I used this as a teaser because Steve used an XHTML doctype on his testpage, but served it as text/html).
So, even though I could have declined, and with my time being quite limited by work and family (and the fact that it's already way past midnight that I'm writing this blogpost) I decided to take up on his request and created my own browsertest:
You can take the test here: implicit HEAD test
Here's some explanation to the labels for the various tests:
Base: A quirksmode document starting with a BASE-element
Explicit: A standards-compliant document that does have an explicit HEAD-element (so in all browsers this should give a positive result)
Quirksmode: A quirksmode document that doesn't have HTML, HEAD or BODY
Valid: A standards-compliant document but with HTML, HEAD and BODY omitted
XHTML: A standards-compliant document with an XHTML doctype and served as application/xhtml+xml that doesn't have a HEAD-element
Note that, as already mentioned above, I do expect most browsers to 'fail' (as in: reporting it to not have a <head>-section in the DOM) the 'XHTML' test since it is an XML application and not SGML (or HTML5). I deliberately skip this test in IE-based browsers since IE doesn't have real XHTML support.
I've tested it with Google Chrome 5 and the Blackberry Browser, which actually performed better.
Also tried IE5 (partly succeeds, but stops halfway through), IE4 and IE3, but they fail the tests.
[Comment edited on maandag 17 mei 2010 08:07]
Xhtml (#4) was skipped while testing with Internet Explorer.
[Comment edited on maandag 17 mei 2010 09:38]
[Comment edited on maandag 17 mei 2010 09:59]
[Comment edited on maandag 17 mei 2010 11:53]
Which is not good, because XHTML should not implicitly populate the header in the DOM tree +)The Yorick wrote on Monday 17 May 2010 @ 11:53:
Tried it on my HTC Desire with the default browser which indentifies as Android 2.1, passed all tests...
Firefox 3.6.3 (Linux) only fails test 4.
Opera 10.53 build 6330 (Linux) only fails test 4.
Sorry, don't have any outdated browsers here....
Comments are closed