<?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>dominykas.com &#187; html</title>
	<atom:link href="http://www.dominykas.com/tag/html.rss2.xml" rel="self" type="application/rss+xml" />
	<link>http://www.dominykas.com</link>
	<description>I&#039;d like to someday write a book about asking the right questions</description>
	<lastBuildDate>Sun, 16 May 2010 22:42:46 +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>Benchmark: HTML outlining/TOC scripts</title>
		<link>http://www.dominykas.com/2010/01/benchmark-html-outlining-toc-scripts.html</link>
		<comments>http://www.dominykas.com/2010/01/benchmark-html-outlining-toc-scripts.html#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:09:12 +0000</pubDate>
		<dc:creator>Dominykas</dc:creator>
				<category><![CDATA[Webbie stuff]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.dominykas.com/?p=68</guid>
		<description><![CDATA[A bit over a week ago Chris Heilmann published a post on table of contents generators, where he listed a couple of JavaScript methods to do that. It&#8217;s been always in the plans to optimize the performance of my own implementation of the HTML5 outlining routine &#8211; and what better way to measure it, than [...]]]></description>
			<content:encoded><![CDATA[<p>A bit over a week ago <a href="http://www.wait-till-i.com/2010/01/06/the-table-of-contents-script-my-old-nemesis/">Chris Heilmann published a post on table of contents generators</a>, where he listed a couple of JavaScript methods to do that. It&#8217;s been always in the plans to optimize the performance of <a href="http://code.google.com/p/h5o/">my own implementation of the HTML5 outlining routine</a> &#8211; and what better way to measure it, than to compare it with some other approaches while I&#8217;m at it. To no surprise, I lost. Big time.</p>
<h2>Results</h2>
<ol>
<li>Chris Heilmann&#8217;s <a href="http://isithackday.com/demos/tocit/toc_yui3.html">YUI based approach</a> (136ms)</li>
<li>Chris Heilmann&#8217;s <a href="http://isithackday.com/demos/tocit/toc_dom.html">DOM based approach</a> (247ms)</li>
<li>Stuart Langridge&#8217;s <a href="http://www.kryogenix.org/code/browser/generated-toc/">generated-toc</a> (258ms)</li>
<li><a href="http://github.com/joshwnj/toc">Josh Johnston&#8217;s solution</a> with jQuery (781ms)</li>
<li>My own <a href="http://code.google.com/p/h5o/">HTML5 Outliner</a> (3099ms)</li>
<li>Chris Heilmann&#8217;s <a href="http://isithackday.com/demos/tocit/toc_js.html">RegExp based approach</a> (4440ms)</li>
<li><a href="http://lab.diogovincenzi.com/blog/view/table-contents-jquery">Diogo Vincenzi&#8217;s solution</a> with jQuery (9334ms)</li>
</ol>
<h3>Methodology</h3>
<p>The numbers above are based on an 1.5Mb file, which has some 200 headings to use for the TOC table. The actual file, was created out of HTML4 specification part on forms, to reflect a more natural usage. The results were a bit different, when I used my own generated file, which had a lot more headings, and a lot less text.</p>
<p>The test runner itself would create an <code>iframe</code>, load the test document inside, inject the required script and call it. The <a href="http://code.google.com/p/h5o/source/browse/trunk/benchmark">source is available</a> on Google Code (though be aware, that you will need to procure and hack the dependencies yourself).</p>
<p>I ran it on a decent 2.2Ghz laptop, using a vanilla version of Portable Firefox 3.5. With some exceptions (see below), the results were comparable and not unexpected in other browsers.</p>
<h2>Insights</h2>
<ul>
<li>The RegExp based approach was a non-contender from the start, as it doesn&#8217;t really work under any browser, other than Firefox.</li>
<li>Diogio&#8217;s solution scored so low because it&#8217;s querying the DOM twice inside every loop iteration (I think).</li>
<li>I am impressed at how well YUI3 performed &#8211; on every browser (incl. IE8), except Opera. I seriously need to follow up on the Opera thing&#8230;</li>
<li>Speaking of YUI3 &#8211; one needs to go through extra hoops to measure performance, due to YUI loader&#8217;s <code>setTimeout()</code>. And make sure that you have all dependencies in on file, to avoid calls to the Yahoo&#8217;s CDN.</li>
<li>IE8 didn&#8217;t like 2Mb documents inside an <code>iframe</code> (hence 1.5Mb)</li>
<li>I have plenty of space for improvement &#8211; it will be fun!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dominykas.com/2010/01/benchmark-html-outlining-toc-scripts.rss2.xml</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC generates invalid ClientIDs</title>
		<link>http://www.dominykas.com/2009/12/asp-net-mvc-generates-invalid-clientids.html</link>
		<comments>http://www.dominykas.com/2009/12/asp-net-mvc-generates-invalid-clientids.html#comments</comments>
		<pubDate>Sat, 19 Dec 2009 16:03:05 +0000</pubDate>
		<dc:creator>Dominykas</dc:creator>
				<category><![CDATA[Webbie stuff]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://www.dominykas.com/?p=40</guid>
		<description><![CDATA[This week I had a joy of spending several hours trying to solve and intermitently happening bug. In short, some 2 times out of 3 the YUI selector utility failed to lookup elements in an XHR loaded HTML fragment. After digging quite deep into the YUI code, I found that it was actually the fault [...]]]></description>
			<content:encoded><![CDATA[<p>This week I had a joy of spending several hours trying to solve and intermitently happening bug. In short, some 2 times out of 3 the <a href="http://developer.yahoo.com/yui/selector/">YUI selector</a> utility failed to lookup elements in an XHR loaded HTML fragment. After digging quite deep into the YUI code, I found that it was actually the fault of the way <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> treats partial views. </p>
<h2>Summary</h2>
<ul>
<li>ASP.NET MVC allows use of ASCX as &#8220;partial views&#8221;</li>
<li>It correctly assumes, that uniqueness of ClientID should be preserved</li>
<li>It incorrectly does not prepend an alpha-character to automatically generated GUID based IDs</li>
<li>User agents and selector libraries may correctly ignore such invalid IDs</li>
<li><a href="http://www.dominykas.com/2009/12/asp-net-mvc-generates-invalid-clientids.html#solution-20091219">Solution: override <code>ViewUserControl.UniqueID</code></a></li>
</ul>
<h2>The problem with ASP.NET MVC</h2>
<p>ASP.NET MVC allows you to return an ASCX control as a view. This allows using a very nice pattern, of loading only parts of the page using XHR, while still being able to use the same controls when the full page is generated.</p>
<p>If you&#8217;ve used ASP.NET enough, then <code>ctl00_something_something</code> must be familliar &#8211; it&#8217;s an automatically generated value for HTML <code>id</code> attributes. ASP.NET does a pretty good job in ensuring that the requirement of unique IDs is followed, however, that only really works for fully generated pages.</p>
<p>If you are returning a partial view to be injected into some page, the context has already been lost &#8211; i.e. the server no longer knows anything about the original counter of controls and unique IDs. To circumvent this problem, MVC uses a GUID as a prefix for the ClientID generation. While, this is an absolutely correct approach, which basically means that ID collision is practically impossible, when you inject your partials into the DOM, the actual implementation has a small bug &#8211; the <a href="http://www.w3.org/TR/html401/types.html#type-name">HTML spec says</a>:</p>
<blockquote><p>ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (&#8220;-&#8221;), underscores (&#8220;_&#8221;), colons (&#8220;:&#8221;), and periods (&#8220;.&#8221;).</p>
</blockquote>
<p>However, as we all know, the GUIDs <em>may</em> start with a number. In fact, they <em>do</em> start with a number much more often than they do with a letter. Which means that your partial views start having situations where <code>id="<strong style="text-decoration:underline;">1</strong>1fa1658-d453-42e0-86f1-e640c476f7ac_ctl02_something_something"</code>. Naturally, if your client side framework is standards aware, it may ignore the <code>id</code> attribute altogether and fail miserably.</p>
<h2>The YUI (non)part of the problem</h2>
<p>In general, the advice is to not use ID attributes as a base for your operations &#8211; be it selecting elements, or attaching events (use classes and wiser selectors instead). In our case, though, we still have a lot of legacy code, which does not follow this approach. There is also the case of Visual Studio sometimes inserting IDs automatically. Still, it doesn&#8217;t matter how IDs end up there &#8211; if you&#8217;re using YUI selector library, you will get some autogenerated IDs anyways.</p>
<p>The reasoning for that, is that querying the DOM using IDs is very cheap with <code>getElementById()</code>. If you&#8217;re supplying a parent element, from which your query should be run, YUI will either re-use the ID that already exists, or will create a new (unique) one for the purposes of expanding your query, i.e. <code>YAHOO.util.Selector.query(".myClass", parentElement)</code> will become <code>"DIV#<i>parentId</i> .myClass"</code> which in turn will be expanded into <code>"DIV[id=<i>parentId</i>] [class=myClass]"</code>, which is still the very same selector, but is easier to parse and process.</p>
<p>Now, the only problem is the regex (<code>'\\#(-?[_a-z]+[-\\w]*)': '[id=$1]'</code>) which does the expanding of ID and class selectors into the attribute based selectors &#8211; it does follow the standard, and only accepts valid values, which means that if your ID starts with a number &#8211; it will not be expanded and the whole query will fail.</p>
<h2 id="solution-20091219">Solution</h2>
<p>While some may say, that YUI should be updated to be more lenient on such errors, I say that there should be no place on the web for invalid code. And there&#8217;s also a much simpler solution to the problem &#8211; override default behaviour of <code>ViewUserControl.UniqueID</code>:</p>
<pre>public class MyViewUserControl : ViewUserControl
{
	public override string UniqueID
	{
		get
		{
			var retval = base.UniqueID;
			if(!string.IsNullOrEmpty(retval)
				&#038;&#038; char.IsDigit(retval[0]))
			{
				retval = "c" + retval;
			}
			return retval;
		}
	}
}
</pre>
<p>Now&#8230; where do I report bugs in ASP.NET MVC?..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dominykas.com/2009/12/asp-net-mvc-generates-invalid-clientids.rss2.xml</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript:void(0) must die</title>
		<link>http://www.dominykas.com/2009/12/javascript-void-must-die.html</link>
		<comments>http://www.dominykas.com/2009/12/javascript-void-must-die.html#comments</comments>
		<pubDate>Wed, 02 Dec 2009 23:32:31 +0000</pubDate>
		<dc:creator>Dominykas</dc:creator>
				<category><![CDATA[Webbie stuff]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.dominykas.com/?p=8</guid>
		<description><![CDATA[Pretty much two weeks ago I dropped my notes from FullFrontal 2009 onto developer&#8217;s forum at work. And one full colleague of mine enquired why did I say that &#8220;javascript:void(0) must die&#8221;. I didn&#8217;t really have a chance to follow it up until now (happy birthday, dear blog).
It doesn&#8217;t do anything, it just sits there!
Now, [...]]]></description>
			<content:encoded><![CDATA[<p>Pretty much two weeks ago I dropped my notes from <a href="http://2009.full-frontal.org/">FullFrontal 2009</a> onto developer&#8217;s forum at work. And one full colleague of mine enquired why did I say that &#8220;<code>javascript:void(0)</code> must die&#8221;. I didn&#8217;t really have a chance to follow it up until now (happy birthday, dear blog).</p>
<h2>It doesn&#8217;t do anything, <a title="Video: Electric Six - Broken Machine" href="http://www.youtube.com/watch?v=pjq3vQV6v-Y">it just sits there</a>!</h2>
<p>Now, normally I&#8217;m not a complete standards freak (unlike the guys working on <a href="http://code.google.com/p/google-caja/">Caja</a>). But what does <code>&lt;a href="javascript:void(0)"&gt;</code> really mean? The answer is simple &#8211; <strong>nothing</strong>.</p>
<p>First of, it&#8217;s a hyperlink to a resource, which should be accessed over Javascript &#8220;protocol&#8221;. Here&#8217;s the problem &#8211; I don&#8217;t really feel that &#8220;javascript&#8221; is a protocol. And it can&#8217;t really handle resources. But lets ignore that. What is the actual resource?</p>
<p>The link tells &#8220;use javascript&#8221; to &#8220;retrieve&#8221;&#8230; <strong>void</strong>. Why would anyone in the world want to view void in their browser? If anyone ever wants to look at it &#8211; they&#8217;re much better off achieving that goal on YouTube&#8230;</p>
<h2>Semantics apart &#8211; it&#8217;s not comprehensible</h2>
<p>Lets suppose, you don&#8217;t really care about web standards and semantics. I&#8217;d probably agree with you &#8211; we&#8217;re quite far away from having a meaningful web (if ever). Still, having crap as the URL is no good &#8211; apparently, <strong>screen readers will read that URL</strong> out loud.</p>
<p>Can you imagine anyone discussing this over a pint: &#8220;You know, I found this great site at <i>javascript colon void opening parenthesis zero closing parenthesis</i>&#8220;? That kind of URL would not make any sense to regular folks.</p>
<h2>Accessibility is NOT about screen readers, though</h2>
<p>Such a link kills browsing experience for sighted users too. Have you ever tried what happens when you <strong>middle-click the void link</strong>? Or right-click and then select &#8220;Open in new tab&#8221;? Here &#8211; <a href="javascript:void(0)" onclick="alert('Firefox and Opera open a background tab, Chrome and IE8 execute onclick JS upon middle click');">try it out</a> (mileage may vary if you use a recent browser).</p>
<p>Exactly &#8211; you guessed it &#8211; <strong>nothing</strong> meaningful happens. Just as it should!</p>
<h2>Solution 1: Use real URLs</h2>
<p>There are several ways out of this. My favorite one is to provide a real URL. If you&#8217;re following progressive enhancement methodology in your work, you always want to provide alternative links to achieve (near full) functionality even when Javascript is disabled.</p>
<p>This means, that instead of having a <code>&lt;a href="javascript:void(0)"&gt;Delete&lt;/a&gt;</code> and attaching <code>onclick</code> handler to it, popping out a confirm dialog and then making a background call using XHR, you provide a link to e.g. <code>/myResource?delete</code> which brings up a form, with a real <code>&lt;button&gt;</code>.</p>
<p>The actual backend code doesn&#8217;t become that much trickier &#8211; you don&#8217;t really have to write up a new &#8220;delete&#8221; routine. By using a confirmation interstitial, you also provide a way to confirm the action, and you can still use a POST request, as this action has permanent effect.</p>
<h2>Solution 2: don&#8217;t use anchor tag</h2>
<p>The above solution doesn&#8217;t always work &#8211; if you have a really interactive application, you&#8217;re not always able to provide links. However, since you&#8217;re already using JS &#8211; why use the <code>&lt;a&gt;</code> tag where it doesn&#8217;t belong?</p>
<p>I did hear some advice, to use <code>&lt;button&gt;</code> for clickable things, which are not really links. You should investigate that, but anyone who has tried to style buttons, knows that it can very easily become a major pain.</p>
<p>Still, you can attach your <code>onclick</code> handlers on anything you want &#8211; <code>div</code>, <code>span</code> and so on. In such cases, you should also add <code>tabindex</code> to make elements focusable and make use of ARIA roles to provide guidelines on behaviour. It&#8217;s not really that hard, now, is it?</p>
<p>The only really painful thing here is providing <code>:hover</code> and <code>:focus</code> styles on IE6. But IE6 should also die, together with <code>javascript:void(0)</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dominykas.com/2009/12/javascript-void-must-die.rss2.xml</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
