document.head

JavaScript performance comparison

Test case created by Mathias Bynens and last updated

Info

How much faster is the HTML5 document.head DOM tree accessor compared to its old-school variant, document.getElementsByTagName('head')[0]?

Preparation code

<script>
  document.head || (document.head = document.getElementsByTagName('head')[0]);
 
  var headList = document.getElementsByTagName('head');
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
document.getElementsByTagName('head')[0]
document.getElementsByTagName('head')[0];
pending…
document.head
document.head;
pending…
querySelector
document.querySelector('head');
pending…
Live nodeList
headList[0];
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

2 comments

David McCormack commented :

If this test is run on a browser which doesn’t support document.head then doesn’t it just use document.getElementsByTagName('head')[0] anyway which makes the results a bit meaningless?

Mathias Bynens (revision owner) commented :

@David: It’s either that or failing the test in those browsers. This test only makes sense in browsers that support document.head.

Add a comment