<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>210 Computing - performance</title>
    <link>http://www.210computing.com/</link>
    <description>Technology Blog for 210 Computing</description>
    <language>en-us</language>
    <copyright>Chris Burkhardt</copyright>
    <lastBuildDate>Wed, 17 Oct 2007 23:09:56 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>admin@packerspundit.com</managingEditor>
    <webMaster>admin@packerspundit.com</webMaster>
    <item>
      <trackback:ping>http://www.210computing.com/Trackback.aspx?guid=ae4a9ddc-6337-4a71-81bc-0e982821c277</trackback:ping>
      <pingback:server>http://www.210computing.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.210computing.com/PermaLink,guid,ae4a9ddc-6337-4a71-81bc-0e982821c277.aspx</pingback:target>
      <dc:creator>Chris Burkhardt</dc:creator>
      <wfw:comment>http://www.210computing.com/CommentView,guid,ae4a9ddc-6337-4a71-81bc-0e982821c277.aspx</wfw:comment>
      <wfw:commentRss>http://www.210computing.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ae4a9ddc-6337-4a71-81bc-0e982821c277</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Accessing properties on the document object
is slow in Internet Explorer. I used to use the document object as a place to store
globals, ie<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span> onclick()
{<br />
document.clicks +=1;<br />
}<br /><br /></span></pre><p>
But this is slow in IE. Instead use:
</p><p></p><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">var</span> clicks;<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span> onclick()
{<br />
clicks += 1;<br />
}</span></pre>
Here is a <a href="http://www.210computing.com/content/binary/documentObject.html" target="_blank">full
page</a> that demonstrates this idea. I use onmousemove to simplify doing an action
over and over, and you can also FEEL how slow it is by moving your mouse around the
page.<br /><br />
And the code: 
<br /><br /><pre><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">&lt;!DOCTYPE
html PUBLIC <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"-//W3C//DTD
XHTML 1.0 Transitional//EN"</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span>&gt;
&lt;html xmlns=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"http://www.w3.org/1999/xhtml"</span> &gt;
&lt;head&gt; &lt;title&gt;Document <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">Object</span> Test&lt;/title&gt;
&lt;script type=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"text/javascript"</span>&gt; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">var</span> totalObj <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> new <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">Object</span>(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">var</span> flag <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> false; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span> loaded()
{ document.onmousemove <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> useDocument;
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span> useDocument()
{ document.total += 5; } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span> useGlobal()
{ totalObj.total += 5; } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span> flip()
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (flag)
{ document.onmousemove <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> useDocument;
document.getElementById('styleType').innerHTML <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> '&amp;nbsp;document
object'; } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span> {
document.onmousemove <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> useGlobal;
document.getElementById('styleType').innerHTML <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> '&amp;nbsp;<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">global</span> object';
} flag <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> !flag;
} &lt;/script&gt; &lt;/head&gt; &lt;body onload=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"loaded();"</span>&gt;
&lt;a href=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#"</span> onclick=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"flip();
return false;"</span>&gt;Click to flip styles&lt;/a&gt;&lt;span id=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"styleType"</span>&gt;
document&lt;/span&gt; &lt;/body&gt; &lt;/html&gt;</span></pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"></span></pre><br /><p></p><img width="0" height="0" src="http://www.210computing.com/aggbug.ashx?id=ae4a9ddc-6337-4a71-81bc-0e982821c277" /></body>
      <title>Javascript document object is slow in IE</title>
      <guid isPermaLink="false">http://www.210computing.com/PermaLink,guid,ae4a9ddc-6337-4a71-81bc-0e982821c277.aspx</guid>
      <link>http://www.210computing.com/2007/10/17/JavascriptDocumentObjectIsSlowInIE.aspx</link>
      <pubDate>Wed, 17 Oct 2007 23:09:56 GMT</pubDate>
      <description>Accessing properties on the document object is slow in Internet Explorer. I used to use the document object as a place to store globals, ie&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt; onclick()
{&lt;br&gt;
document.clicks +=1;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
But this is slow in IE. Instead use:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var&lt;/span&gt; clicks;&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt; onclick()
{&lt;br&gt;
clicks += 1;&lt;br&gt;
}&lt;/span&gt;&lt;/pre&gt;
Here is a &lt;a href="http://www.210computing.com/content/binary/documentObject.html" target="_blank"&gt;full
page&lt;/a&gt; that demonstrates this idea. I use onmousemove to simplify doing an action
over and over, and you can also FEEL how slow it is by moving your mouse around the
page.&lt;br&gt;
&lt;br&gt;
And the code: 
&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;!DOCTYPE
html PUBLIC &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"-//W3C//DTD
XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&amp;gt;
&amp;lt;html xmlns=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt; &amp;gt;
&amp;lt;head&amp;gt; &amp;lt;title&amp;gt;Document &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;Object&lt;/span&gt; Test&amp;lt;/title&amp;gt;
&amp;lt;script type=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"text/javascript"&lt;/span&gt;&amp;gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var&lt;/span&gt; totalObj &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; new &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;Object&lt;/span&gt;(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var&lt;/span&gt; flag &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; false; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt; loaded()
{ document.onmousemove &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; useDocument;
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt; useDocument()
{ document.total += 5; } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt; useGlobal()
{ totalObj.total += 5; } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt; flip()
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (flag)
{ document.onmousemove &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; useDocument;
document.getElementById('styleType').innerHTML &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; '&amp;amp;nbsp;document
object'; } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; {
document.onmousemove &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; useGlobal;
document.getElementById('styleType').innerHTML &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; '&amp;amp;nbsp;&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;global&lt;/span&gt; object';
} flag &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; !flag;
} &amp;lt;/script&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body onload=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"loaded();"&lt;/span&gt;&amp;gt;
&amp;lt;a href=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#"&lt;/span&gt; onclick=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"flip();
return false;"&lt;/span&gt;&amp;gt;Click to flip styles&amp;lt;/a&amp;gt;&amp;lt;span id=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"styleType"&lt;/span&gt;&amp;gt;
document&amp;lt;/span&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.210computing.com/aggbug.ashx?id=ae4a9ddc-6337-4a71-81bc-0e982821c277" /&gt;</description>
      <comments>http://www.210computing.com/CommentView,guid,ae4a9ddc-6337-4a71-81bc-0e982821c277.aspx</comments>
      <category>javascript</category>
      <category>js</category>
      <category>performance</category>
    </item>
  </channel>
</rss>