<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Calyptus Life &#187; DOM</title>
	<atom:link href="http://blog.calyptus.eu/tags/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.calyptus.eu</link>
	<description>Advanced web application development tactics - from scalability to UI design</description>
	<lastBuildDate>Wed, 28 Dec 2011 10:31:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Performance of .nodeName</title>
		<link>http://blog.calyptus.eu/seb/2009/11/the-performance-of-nodename/</link>
		<comments>http://blog.calyptus.eu/seb/2009/11/the-performance-of-nodename/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 05:43:01 +0000</pubDate>
		<dc:creator>Sebastian Markbåge</dc:creator>
				<category><![CDATA[Client Side]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.calyptus.eu/?p=177</guid>
		<description><![CDATA[I was researching various options of traversing nodes for Slick and the DOM Range for MooTools. I realized that the nodeName property is incredibly slow to access in WebKit browsers. This is because it is working with qualified names (with namespaces and stuff) internally.

if &#40;node.nodeName == 'A'&#41; // do something with anchor tag

If you add [...]]]></description>
			<content:encoded><![CDATA[<p>I was researching various options of traversing nodes for <a href="http://github.com/subtleGradient/slick">Slick</a> and the <a href="http://github.com/calyptus/mootools-more/tree/range/Source/Native/">DOM Range for MooTools</a>. I realized that the nodeName property is incredibly slow to access in WebKit browsers. This is because it is working with qualified names (with namespaces and stuff) internally.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p1773"><td class="code" id="p177code3"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// do something with anchor tag</span></pre></td></tr></table></div>

<p>If you add case insensitive matching to that it will be even slower.</p>
<p>Instead I decided to try to check the constructor of the node to determine what type it is. For example for the anchor (A) tag, modern browsers will use the prototype of HTMLAnchorElement. This can potentially speed up these checks if you&#8217;re looking for a known node type.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p1774"><td class="code" id="p177code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">constructor</span> <span style="color: #339933;">===</span> HTMLAnchorElement<span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// do something</span>
<span style="color: #006600; font-style: italic;">// OR...</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>node <span style="color: #000066; font-weight: bold;">instanceof</span> HTMLAnchorElement<span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// do something</span></pre></td></tr></table></div>

<p>I ran <a href="http://labs.calyptus.eu/NodeName/performance-test.html">this performance test</a> in various browsers. It traverses all nodes in a large HTML documents and checks which ones are anchor nodes. It first does a blank run to eliminate any initialization quirks. Then it does a control run without the anchor check. Then it tests each of the above models.</p>
<p><strong>IE6 and IE7</strong> will obviously fail since they don&#8217;t support the HTMLAnchorElement constructor/prototype. For that case you would have to fall back to the nodeName property.</p>
<p><strong>IE8</strong> will be slightly slower with the constructor check than the nodeName check. But the difference is marginal in the overall scope of IE&#8217;s slowness.</p>
<p><strong>WebKit</strong> will gain significant performance using the constructor check. The difference is relatively small to the overhead of manually walking the tree. However, if you take the control value from the blank run into account, the difference of just the node type checks will be significant (several times faster). The slow part is the WebKit DOM API, so you will see this with both JavaScriptCore and V8 (Safari and Chrome respectively).</p>
<p><strong>Firefox</strong> will be slower on the first run for some weird reason. But in subsequent runs the constructor check will be faster than the nodeName check.</p>
<p><em>As a side note, node.tagName is no different. That is just an alias for node.nodeName.</em></p>
<p><em>In <a href="http://ejohn.org/blog/nodename-case-sensitivity/">John Resig&#8217;s case sensitivity</a> he discusses the case inconsistencies of the nodeName property in various contexts and the impact on performance. For example, in IE, the value of nodeName of unknown elements (like the new HTML5 elements) keeps it original case as in the markup.</em></p>
<p><em>This means that any proper CSS selector search for such elements would have to run a case-insensitive match against the nodeName property. Unfortunately the little trick I&#8217;ve shown above doesn&#8217;t remedy this problem because unknown elements will be lacking a known constructor. However, known Elements can still utilize this trick as a slight performance boost, while letting unknown element fallback to a case insensitive match.</em></p>
<p><em>UPDATE: I added a case-insensitive match to the <a href="http://labs.calyptus.eu/NodeName/performance-test.html">performance tests</a> using regular expressions &#8211; showing the added overhead compared to constructor checking.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.calyptus.eu/seb/2009/11/the-performance-of-nodename/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HTML 5 Current Browser Support &#8211; Part 1 &#8211; Introduction</title>
		<link>http://blog.calyptus.eu/seb/2009/03/html-5-current-browser-support-part-1-introduction/</link>
		<comments>http://blog.calyptus.eu/seb/2009/03/html-5-current-browser-support-part-1-introduction/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 23:02:13 +0000</pubDate>
		<dc:creator>Sebastian Markbåge</dc:creator>
				<category><![CDATA[Client Side]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Compatibility]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[WHATWG]]></category>

		<guid isPermaLink="false">http://blog.calyptus.eu/?p=44</guid>
		<description><![CDATA[The HTML 5 working draft is continuing it&#8217;s development of the future support for HTML 5. This includes new tags, attributes and a strong specification of how clients should interact with old and new elements. What I find even more intriguing, is the standardization of many advanced JavaScript DOM features (such as editable content, drag [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.whatwg.org/specs/web-apps/current-work/">HTML 5 working draft</a> is continuing it&#8217;s development of the future support for HTML 5. This includes new tags, attributes and a strong specification of how clients should interact with old and new elements. What I find even more intriguing, is the standardization of many advanced JavaScript DOM features (such as editable content, drag and drop). Most of which has been available to IE users for more than a decade. This is one area that standards has been particularly slow to adopt. With the current beta versions of Safari, Chrome and Firefox these new browsers are finally ready to leave IE behind (yes, even IE 8).</p>
<p>Many people are still frightened of implementing code according to a working draft. Especially since it&#8217;s <a href="http://wiki.whatwg.org/wiki/FAQ#When_will_HTML_5_be_finished.3F">not scheduled to be complete until 2012</a>. In my opinion, those fears are largely unfounded at this point. The primary reason for this is that many of the features have been available in IE for many years and the <a href="http://www.whatwg.org/specs/web-apps/current-work/">HTML 5 specification</a> centers around keeping some historical compliance. So the primary threat for lagging cross browser functionality has already been eliminated. It is also the <a href="http://www.whatwg.org/">WHATWG</a>&#8217;s estimate that browsers will have full compliance and people will have started utilizing this new standard long before it is finalized. For these reasons, by the time you read this, you may already be a late adopter.</p>
<p>However, there are still some quirks that you need to be aware of. I&#8217;ve been working on cross browser layers of the HTML 5 specifications since 2007 including backwards compatible code for older browsers. This code has been used in production and little of it has changed since mid-2008. Therefore I&#8217;ve <a href="http://github.com/calyptus">started work</a> on introducing these features to my JavaScript framework of choice, <a href="http://www.mootools.net/">MooTools</a>. While I refactor my code for this purpose I thought I might introduce some of the quirks that you might come across in your own endeavors.</p>
<p><strong>Coming up</strong></p>
<p>Part 2 &#8211; Drag and Drop, Copy and Paste</p>
<p>Part 3 &#8211; Range and Selection</p>
<p>Part 4 &#8211; ContentEditable and ExecCommand</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.calyptus.eu/seb/2009/03/html-5-current-browser-support-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

