title: For performance purposes, is "document" better off as one global variable or repeated hundreds of times locally?
body: <p>I am not sure if Stack Overflow is the right forum for this particular question but here goes. I am trying to trim the fat out of my external js file. I came across this article: </p>
  
  <p>[<a href="http://oreilly.com/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html" rel="nofollow">http://oreilly.com/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html</a><a href="http://oreilly.com/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html" rel="nofollow">1</a></p>
  
  <p>I scanned my js file and found 250 instances of <strong>document</strong> in various functions, e.g.,</p>
  
  <pre><code>function first() {
      document.getElementById('id1').style.display = 'none';
      alert('Hi');
  }
  
  function second() {
      document.getElementById('id2').innerHTML = 'foo bar';
      alert('Hello');
  }
  //etc
  </code></pre>
  
  <p>I can leave these 250 or so lines as is or trim about 1.7 kB out of my file by writing (note: no other variables in any function are named d):</p>
  
  <pre><code>var d = document;
  
  function first() {
      d.getElementById('id1').style.display = x;
      alert('Hi');
  }
  
  function second() {
      d.getElementById('id2').innerHTML = y;
      alert('Hello');
  }
  //etc
  </code></pre>
  
  <p>I understand the article in the link, but for page speed wouldn't it be better to initialize <strong>document</strong> one time as a global (assuming no refreshes/reloads), keep it in memory, and then have it at the ready 250 times for the other functions?</p>