<?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>Andrea Trasatti&#039;s tech notes and more &#187; Mobile</title>
	<atom:link href="http://blog.trasatti.it/category/mobile/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.trasatti.it</link>
	<description></description>
	<lastBuildDate>Tue, 18 Dec 2012 01:36:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Measuring the speed of resource loading with JavaScript and HTML5</title>
		<link>http://blog.trasatti.it/2012/12/measuring-the-speed-of-resource-loading-with-javascript-and-html5.html</link>
		<comments>http://blog.trasatti.it/2012/12/measuring-the-speed-of-resource-loading-with-javascript-and-html5.html#comments</comments>
		<pubDate>Mon, 10 Dec 2012 21:55:28 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[HAR]]></category>
		<category><![CDATA[IE10]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[nokia_dev]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=722</guid>
		<description><![CDATA[This is a follow up article to Measuring site performance with JavaScript on mobile, I suggest you read it before you continue. In the previous article I talked about the Navigation Timing spec, here I will talk about the Performance Timeline and Resource Timing specs and how they work in IE10, the first browser to implement [...]]]></description>
				<content:encoded><![CDATA[<p>This is a follow up article to <a title="Measuring site performance with JavaScript on mobile" href="http://blog.trasatti.it/2012/11/measuring-site-performance-with-javascript-on-mobile.html">Measuring site performance with JavaScript on mobile</a>, I suggest you read it before you continue. In the previous article I talked about the <a title="Navigation Timing" href="http://www.w3.org/TR/navigation-timing">Navigation Timing</a> spec, here I will talk about the <a title="Performance Timeline" href="http://www.w3.org/TR/performance-timeline">Performance Timeline</a> and <a title="Resource Timing" href="http://www.w3.org/TR/resource-timing">Resource Timing</a> specs and how they work in IE10, the first browser to implement them. I created a page that shows some of the data available and a library that generates a <a title="HTTP archive" href="http://www.softwareishard.com/blog/firebug/http-archive-specification/">HAR</a> that you can later analyse.</p>
<p><span id="more-722"></span></p>
<h2>Showing basic performance details of page resources</h2>
<p>The Performance Timeline is a spec that extends the <a title="window.performance" href="http://www.w3.org/TR/navigation-timing/#performance">Performance</a> interface defined in the Navigation Timing spec and adds a new interface called <code>PerformanceEntry</code>. The new additions give to developers a quick overview of the performance of each resource that composes the page and the order in which each resource was loaded. For anyone that wants to quickly see the timing information of the page this is more than enough and very easy to use. Below you can see the most basic use of the API:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> simplePerf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">var</span> pe <span style="color: #339933;">=</span> performance.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> pe.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span><span style="color: #009900;">&#41;</span> console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Name: &quot;</span> <span style="color: #339933;">+</span> pe<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">+</span> 
   <span style="color: #3366CC;">&quot; Start Time: &quot;</span> <span style="color: #339933;">+</span> pe<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">startTime</span> <span style="color: #339933;">+</span> 
   <span style="color: #3366CC;">&quot; Duration: &quot;</span> <span style="color: #339933;">+</span> pe<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">duration</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Once you have a list of the resources that the browser has loaded you can further explore the details of each HTTP request. Similarly to the Navigation Timing API developers have access to the timings of any redirects, DNS lookups, network connections and of course the time to make the actual request and receive the response. For each resource is also available the <code>initiatorType</code>, i.e. how the resource is referenced in the HTML page; the types available are &#8221;css&#8221;, &#8220;embed&#8221;, &#8220;img&#8221;, &#8220;link&#8221;, &#8220;object&#8221;, &#8220;script&#8221;, &#8220;subdocument&#8221;, &#8220;svg&#8221;, &#8220;xmlhttprequest&#8221;, &#8220;other&#8221;. If you have IE10 on your Windows PC or a Windows Phone 8 device you can visit <a title="Performance Timing API example" href="http://logme.mobi/jsnt/perftime.html">this page</a> and try yourself.</p>
<div id="attachment_763" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/12/wp_ss_20121206_0001.png"><img class="size-medium wp-image-763 " title="Performance Timeline" src="http://blog.trasatti.it/wp-content/uploads/2012/12/wp_ss_20121206_0001-300x180.png" alt="" width="300" height="180" /></a><p class="wp-caption-text">Start time and duration of each resource</p></div>
<div id="attachment_764" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/12/wp_ss_20121206_0003.png"><img class="size-medium wp-image-764 " title="Resource Timing details" src="http://blog.trasatti.it/wp-content/uploads/2012/12/wp_ss_20121206_0003-300x180.png" alt="" width="300" height="180" /></a><p class="wp-caption-text">Breakdown of the time it took to load each resource in the page. Values are grouped by Network, Request and Response.</p></div>
<h3>How does it work?</h3>
<p>The example is made of 4 parts, the HTML itself, a tiny CSS file to give a minimal styling to the tables, a JavaScript that does most of the work and a couple of images. The code is available on Projects.</p>
<p><code>onload</code>, <code>featureDetect()</code> is fired. <code>featureDetect()</code> checks the browser support for the Performance Timeline and Resource Timings specs and shows a message in the page. If supported, it also enables the two buttons. This is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> featureDetect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">var</span> rt <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Oh rats! Your browser does not support the Resource Timing spec :(&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">var</span> pt <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Oh rats! Your browser does not support the Performance Timeline spec :(&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!!</span>window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  pt <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Excellent! Your browser supports the Performance Timing spec&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   rt <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Excellent! Your browser supports the Resource Timing spec&quot;</span><span style="color: #339933;">;</span>
   document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myButton2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disabled</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
   document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myButton3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disabled</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'perf_support'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> 
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'perf_support'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+</span>
  rt <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span> <span style="color: #339933;">+</span> pt <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If the user clicks on &#8220;Load another image&#8221; the function <code>loadResources()</code> is fired. All this function does is create a new <code>image()</code> and append it after the existing image, this is useful to display more timing data, more on this later. <code>loadResources()</code> on its own is not very interesting and you should not spend time on this. What is interesting to see is that the browser continues keeping track of all the events and the information is available via JavaScript. Notice that I use a PHP script to delay the delivery of the image; the only reason is to make sure that the response time is a big enough number.</p>
<p>Clicking on &#8220;Display basic performance data&#8221; a table is shown. The table is printed by the function <code>displayPerfData()</code> which takes <code>window.performance.getEntries()</code> and loops through the elements to show when the browser started loading each element and how long it took to load it. The script uses the <code>duration</code> property to access the final timing. For basic measurements this is probably all you need to know, easy, hu?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> displayPerfData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!!</span>window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> perf_data <span style="color: #339933;">=</span> loadPerfTimeData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'perf_data'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">+</span> perf_data <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">function</span> loadPerfTimeData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">var</span> perf_data <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;table id='table_perf_data'&gt;
  &lt;thead&gt;&lt;tr&gt;&lt;td&gt;Resource&lt;/td&gt;&lt;td&gt;Start time (ms)&lt;/td&gt;
  &lt;td&gt;Duration (ms)&lt;/td&gt;&lt;/tr&gt;&lt;/thead&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tbody&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;document&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;tr&gt;&lt;td&gt;HTML document&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
   perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;tr&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^.*\/|\.$/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">startTime</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">duration</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/tbody&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">return</span> perf_data<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The browser provides the values for the start time and the duration in accordance to the <a title="High Resolution Time spec" href="http://www.w3.org/TR/hr-time/">High Resolution Time spec</a>. The start time is particularly interesting because it shows exactly when the browser initiated the request for the object. This also means that the browser keeps track of when the user clicked on &#8220;Load another image&#8221;.</p>
<p>Similarly, &#8220;Display detailed performance data&#8221; loops through <code>getEntries()</code> to get a list of the resources the browser loaded, but instead goes into more details and breaks down the data into network-related operations (DNS lookup, open the connection, SSL, etc), request time and response time. For my example I bundled up the timings into three buckets, network, request, response, refer to the <a title="Resource Timing | Processing model" href="http://www.w3.org/TR/resource-timing/#processing-model">Processing model</a> for a detail of all available properties. In my tests the request time was often close to zero when using a Wifi. For the sake of readability I have rounded the timings. This is how it works:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> displayDetailedPerfData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!!</span>window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> loadResTimData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'detailed_perf_data'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">+</span> d <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">function</span> loadResTimData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">getEntries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">var</span> perf_data <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;table id='table_perf_data'&gt;&lt;thead&gt;&lt;tr&gt;
  &lt;td&gt;Resource&lt;/td&gt;&lt;td&gt;Network (ms)&lt;/td&gt;&lt;td&gt;Request (ms)&lt;/td&gt;
  &lt;td&gt;Response (ms)&lt;/td&gt;&lt;/tr&gt;&lt;/thead&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tbody&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;document&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// for the document refer to window.performance.timing instead,</span>
   <span style="color: #006600; font-style: italic;">// we skip it for this example</span>
   <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;tr&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^.*\/|\.$/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">requestStart</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// resource is cached, some entries are zero, </span>
   <span style="color: #006600; font-style: italic;">// we default to fetchStart instead</span>
   perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span><span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">fetchStart</span><span style="color: #339933;">-</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">startTime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
   perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span><span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">requestStart</span><span style="color: #339933;">-</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">startTime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span><span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseStart</span><span style="color: #339933;">-</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">requestStart</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  perf_data <span style="color: #339933;">=</span> perf_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">+</span><span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseEnd</span><span style="color: #339933;">-</span>e<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseStart</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
  perf_data <span style="color: #339933;">=</span> perf_data <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 perf_data <span style="color: #339933;">=</span> perf_data <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/tbody&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">return</span> perf_data<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>While I was writing the script I also thought of another example, but eventually decided to take it out as I did not find a suitable use in my specific use case. What I wanted to show was how you can also query for specific entries and filter by type looking at the <code>initiatorType</code>. What I initially thought was to fire an event once the extra image is loaded and show data about it specifically. I thought it was interesting to attach an <code>onload</code> event to a resource that I am loading at a later stage and measure its performance, but the example is so small that it did not fit. If you are curious look at <code>resourceTiming()</code>. First of all I get a list of objects filtering by type &#8220;resource&#8221;, this means I will get a list of objects such as images and stylesheets, then I loop through them and filter out everything but images. Calculating the time it took to load it is a matter of making a subtraction.</p>
<p>The source code is available on <a href="https://github.com/atrasatti/jsperfexamples/tree/master/restime">GitHub</a>.</p>
<h3>When to check the performance object?</h3>
<p>In my example I decided to use a button for two reasons, I wanted to make sure it happens once all the parts of the page are loaded and I wanted to allow visitors to load the extra image and then refresh the timings.</p>
<p>Truth is, there isn&#8217;t a <strong>right</strong> time to access the <code>performance</code> object, it depends on your application. If your script makes an XHR request, loads images dynamically or anything else you can always check both when the operation started and how long it took. The &#8220;Load another image&#8221; button is an example, more complex Web apps might have much more meaningful reasons to monitor the performance tied to specific events other than <code>onload</code>.</p>
<h2>Browser support</h2>
<p>The specs described here are really new, infact they are just candidate or proposed recommendations, so we cannot expect full support across all browsers. IE10 both on Windows 8 and Windows Phone 8 is the first browser to support them. Yes, you read that right, IE10 is ahead of the pack on this one. Chrome is expected to implement it soon and Mozilla is a member of the Web Perf WG, so we can expect it there too.</p>
<h2>Create HAR</h2>
<p>While researching on performance I started looking into a packaging format called HAR. Both Firebug on Chrome&#8217;s developer tools can generate a HAR (basically a JSON file) of your session. The good thing about HAR is that you can store it and analyse it later and see the performance of one or more pages. For your production Web site you probably want to build something scalable, that will read a lot of data and aggregate it, you might want to do it in-house or you might want to use a third-party service. On the other hand, while you are creating a new Web app you might want to monitor specific pages or specific parts of your app and you want to do it with high level of detail. For this use case I thought that creating a HAR and posting it to a remote server could be a nice feature. What you do with the HAR posted is up to you, in my case I simply view it with an online tool called <a title="HAR Viewer" href="http://www.softwareishard.com/har/viewer/">HAR online Viewer</a>.</p>
<p>So let&#8217;s start from the basics: <a title="HAR 1.2 spec" href="http://www.softwareishard.com/blog/har-12-spec/">HAR 1.2 spec</a>. What we want to do is build a JSON with all the information about the current page and store it somewhere. In my example I do this for a single page, you might want to use a session or store it somewhere (localStorage?) and then make a single POST with all the information you need.</p>
<p>My example is composed of two parts, the HTML and JavaScript that runs in the client and a very simple PHP script on the server that stores the file locally.</p>
<h3>The markup</h3>
<p>For this sort of example the markup you need is very limited, but to make it more similar to a regular Web page I added a stylesheet, an image, some text and a couple of third-party scripts (Twitter and Facebook buttons and Google analytics). Three links are available, &#8220;Generate HAR&#8221; which will fire the script to generate a HAR file and POST it to the server. The script will also check that your browser implements the Performance Timeline and Resource Timing specs, if not it will do nothing. Assuming your browser can provide the needed information, clicking on &#8220;See the dynamically generated HAR on HAR viewer&#8221; will show you the HAR of your current session. Please note that although the page works on modern mobile browsers it is designed for a big screen. If you are using a browser that does not implement the needed API&#8217;s you can click on &#8220;See a HAR file generated from a previous session with a Lumia 920 running IE10 Mobile on HAR viewer&#8221; and see a session I recorded previously.</p>
<h3>The scripts</h3>
<p>For this example I use two scripts, I use PPK&#8217;s <a title="Browser detect" href="http://www.quirksmode.org/js/detect.html">browser detect</a> and a script I created.<br />
My script is very simple in concept, there are a number of values that I must provide for a valid HAR 1.2 JSON and I read them from either the <code>performance</code> object or from the <code>window</code> and <code>document</code> objects.</p>
<p><code>generateHAR()</code> is where it all starts, I collect some basic details about the browser, the page title and initial timings.<br />
<code>fillEntries()</code> is where most of the work happens. Although simple in concept there are few things to be noted. The fields that HAR supports and those provided by the Resource Timing API don&#8217;t match exactly so I had to make some adjustments. For example HAR has a field called &#8220;blocked&#8221; that represents the time the browser waited for an available slot, but this information is not available in the Resource Timing API. Similarly the Resource Timing API exposes information about redirects that are not part of HAR. I tried to bundle together what made sense.<br />
HAR requires integer numbers, so I round all values. Because of this the generated HAR occasionally failed to validate as the numbers did not add up exactly to the total time. From my tests the rounding occasionally generated an error of 1 or 2ms, so I decided to use the &#8220;wait&#8221; field for which I had no data anyway. When the rounding makes the sum of the intervals smaller than the total I set the &#8220;wait&#8221; field to the difference in time, when it&#8217;s smaller I actually decrease the total time (I know, dirty). Here is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">twait <span style="color: #339933;">=</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">duration</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> tdns <span style="color: #339933;">-</span> tconnect <span style="color: #339933;">-</span> tsend <span style="color: #339933;">-</span> treceive <span style="color: #339933;">;</span>
ttime <span style="color: #339933;">=</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">duration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>twait<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 ttime <span style="color: #339933;">=</span> ttime<span style="color: #339933;">-</span>twait<span style="color: #339933;">;</span>
 twait<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Probably the most interesting thing I learnt while writing the script is that some of the timings will be empty (this is actually <strong>by spec</strong>!). Imagine the previous example where I was displaying data about a page; the second image is loaded dynamically, fired by a user event (clicking the button), if you try to calculate the time it took to load, fields like <code>responseEnd</code> will be empty until the image has finished loading. Similarly, if there were no redirects, <code>redirectStart</code> and <code>redirectEnd</code> will be empty, so if you try to make operations with those you will get unexpected results. What is ALWAYS set is <code>startTime</code>, so I added a few extra checks to make sure the starting time in all my subtractions is set:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">nextFrame <span style="color: #339933;">=</span> rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">startTime</span><span style="color: #339933;">;</span>
tdns <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">domainLookupEnd</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">domainLookupEnd</span><span style="color: #339933;">-</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">startTime</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tdns<span style="color: #009900;">&#41;</span> nextFrame <span style="color: #339933;">=</span> rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">connectStart</span><span style="color: #339933;">;</span>
tconnect <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">connectEnd</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">connectEnd</span><span style="color: #339933;">-</span>nextFrame<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tconnect<span style="color: #009900;">&#41;</span> nextFrame <span style="color: #339933;">=</span> rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">requestStart</span><span style="color: #339933;">;</span>
tsend <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseStart</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseStart</span><span style="color: #339933;">-</span>nextFrame<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tsend<span style="color: #009900;">&#41;</span> nextFrame <span style="color: #339933;">=</span> rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseStart</span><span style="color: #339933;">;</span>
treceive <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseEnd</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">responseEnd</span><span style="color: #339933;">-</span>nextFrame<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<div id="attachment_765" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/12/wp_ss_20121206_0002.png"><img class="size-medium wp-image-765" title="Resource timing with responseEnd=0" src="http://blog.trasatti.it/wp-content/uploads/2012/12/wp_ss_20121206_0002-300x180.png" alt="" width="300" height="180" /></a><p class="wp-caption-text">Notice how the response time is a negative number, this is because the image hasn&#8217;t finished loading and so responseEnd is still 0</p></div>
<p>Internet Explorer also supports the property <code>fileSize</code> for documents and images. I implemented the support for it and kept the default value of -1 for the other browsers.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">fileSize <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
httpStatus <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;200&quot;</span><span style="color: #339933;">;</span>
httpText <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;OK&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;document&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 fileSize <span style="color: #339933;">=</span> document.<span style="color: #660066;">fileSize</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// a dumb check to see if fileSize is supported, of course you </span>
<span style="color: #006600; font-style: italic;">// MUST have at least 1 image in your page</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!!</span>imgs<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">fileSize</span> <span style="color: #339933;">&amp;&amp;</span> rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">initiatorType</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>ii<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>ii<span style="color: #339933;">&lt;</span>imgs.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>ii<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>imgs<span style="color: #009900;">&#91;</span>ii<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">==</span> rl<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// it looks like fileSize is -1 when image is loaded from cache.</span>
   <span style="color: #006600; font-style: italic;">// Not documented</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>imgs<span style="color: #009900;">&#91;</span>ii<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">fileSize</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    fileSize <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    httpStatus <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;304&quot;</span><span style="color: #339933;">;</span>
    httpText <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Not Modified&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    fileSize <span style="color: #339933;">=</span> imgs<span style="color: #009900;">&#91;</span>ii<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">fileSize</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Once all is ready I generate a JSON and POST it to the server. All sessions are stored on the server, but there is a cronjob that removes them after 7 days.</p>
<p>If you have a computer or a device with IE10 you can try this at <a title="HAR Generator" href="http://logme.mobi/jsnt/har.html">http://logme.mobi/jsnt/har.html</a> or you can look at a <a href="http://www.softwareishard.com/har/viewer/?inputUrl=http://logme.mobi/jsnt/harp/store/0c8f0f589bf0c8e289737d936627e7f9">previous session</a> that I created with a Lumia 920. The source code is available on <a href="https://github.com/atrasatti/jsperfexamples/tree/master/har_generator">GitHub</a>.</p>
<h3>TODO</h3>
<p>I noticed that the HTML page has a total duration that is equal to loading the entire page and all its resources. I am investigating how to get the actual data for the HTML alone. If I can, I will fix it later.</p>
<h2>Performance and RUM tools</h2>
<p>There are a number of tools out there that already take care of measuring the page performance on the client. Google Analytics probably gives the simplest overview and for free. If you are looking for something more advanced you should check out a couple of open source projects: <a title="Boomerang" href="https://github.com/bluesmoon/boomerang">Boomerang</a> and <a title="Web Episodes 2" href="http://stevesouders.com/episodes2/">Web Episodes</a> are both framework for timing web pages. They offer different degrees and techniques to measure page performance, but they are both a lot more advanced than my examples and they cater for all the browsers in the market today. If you like the idea, but want to rely on a professional to take care of this, I suggest you check out <a title="lognormal" href="http://www.lognormal.com">lognormal</a> (developers of Boomerang) and <a title="Torbit" href="http://torbit.com">Torbit</a> (who use Steve Souders&#8217; Web Episodes).</p>
<h2>Resources</h2>
<ul>
<li>W3C’s <a title="Web Performance publications" href="http://www.w3.org/wiki/Web_Performance/Publications">Web performance WG publications</a> (see all the specs the group is working on and their status)
<ul>
<li><a title="Navigation timing" href="http://www.w3.org/TR/navigation-timing/">Navigation Timing</a> (PR as of 26 Jul 2012)</li>
<li><a title="High resolution time" href="http://www.w3.org/TR/hr-time/">High Resolution Time</a> (PR as of 23 Oct 2012)</li>
<li><a title="Resource timing" href="http://www.w3.org/TR/resource-timing/">Resource Timing</a> (CR as of May 2012)</li>
</ul>
</li>
<li><a title="Navigation Timing (Windows)" href="http://msdn.microsoft.com/en-us/library/ie/hh673552(v=vs.85).aspx">Navigation Timing</a> documentation on MSDN</li>
<li>Performance Timeline and Resource Timing example <a href="https://github.com/atrasatti/jsperfexamples/tree/master/restime">source code</a></li>
<li><a title="Boomerang" href="https://github.com/bluesmoon/boomerang">Boomerang</a> library</li>
<li><a title="Web Episodes 2" href="http://stevesouders.com/episodes2/">Web Episodes</a> library</li>
<li><a title="HAR Viewer" href="http://www.softwareishard.com/har/viewer/">HAR online Viewer</a> and other <a title="HAR Adopters" href="http://www.softwareishard.com/blog/har-adopters/">HAR adopters</a></li>
<li><a href="https://github.com/atrasatti/jsperfexamples/tree/master/har_generator">HAR generator</a> source code</li>
</ul>
<p>This article is a cross-post from <a title="Measuring the speed of resource loading with JavaScript and HTML5" href="http://www.developer.nokia.com/Blogs/Code/2012/12/10/measuring-the-speed-of-resource-loading-with-javascript-and-html5/">Measuring the speed of resource loading with JavaScript and HTML5</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2012/12/measuring-the-speed-of-resource-loading-with-javascript-and-html5.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Measuring site performance with JavaScript on mobile</title>
		<link>http://blog.trasatti.it/2012/11/measuring-site-performance-with-javascript-on-mobile.html</link>
		<comments>http://blog.trasatti.it/2012/11/measuring-site-performance-with-javascript-on-mobile.html#comments</comments>
		<pubDate>Mon, 19 Nov 2012 18:37:37 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[IE10]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[Nokia]]></category>
		<category><![CDATA[nokia_dev]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=639</guid>
		<description><![CDATA[There is a lot of talk around responsive Web design being too slow or too resource intensive and that other methodologies can achieve better performance. I don&#8217;t want to go into the details of which approach is better because I think different scenarios require different solutions. What is certainly true in all cases is that [...]]]></description>
				<content:encoded><![CDATA[<p>There is a lot of talk around responsive Web design being too slow or too resource intensive and that other methodologies can achieve better performance. I don&#8217;t want to go into the details of which approach is better because I think different scenarios require different solutions. What is certainly true in all cases is that a Web site or app that loads faster is better than one that is slow. Companies like <a title="Speed matters" href="http://googleresearch.blogspot.com/2009/06/speed-matters.html">Google</a>, <a title="Web speed survey" href="http://www.gomez.com/wp-content/downloads/GomezWebSpeedSurvey.pdf">Gomez</a> and <a title="Akamai Reveals 2 Seconds as the New Threshold of Acceptability for eCommerce Web Page Response Times" href="http://www.akamai.com/html/about/press/releases/2009/press_091409.html">Akamai</a> have all published papers and survey results showing how speed affects user perception of a service from your desktop computer and even more on a mobile device (KISSmetrics has also drawn a nice <a title="Loading time infographic" href="http://blog.kissmetrics.com/loading-time/">infographic</a> for the lazy ones). This is the first article and another one will follow shortly.<span id="more-639"></span></p>
<h2>The Navigation Timing API</h2>
<p>Up until recently browsers have taken care of everything around resource prioritization, memory management and resource loading. With the rise of JavaScript, Web developers feel the need to be more in control and at the same time have more responsibility. If a Web app requires a lot of resources you might want to tweak what you load when based on the actual performance loading a page. The W3C has a number of specs in the works, some of which already implemented by browsers, that allow Web developers to measure how quickly Web contents are loaded. The <a title="Navigation timing" href="http://www.w3.org/TR/navigation-timing/">Navigation Timing</a> API is already implemented by IE (9 and later), Chrome and Firefox on the desktop (also see <a title="can I use | Navigation timing" href="http://caniuse.com/nav-timing">can I use</a>) and on mobile by IE9 and later, Android 4.1 and Chrome on Android.<br />
You are probably all familiar with WebKit inspector&#8217;s resources panel; look at this screenshot from an early implementation of the page resources, here you can see how long each resource took to load and you have details about when the request started, how long the browser waited and how long it took to transfer.</p>
<div id="attachment_642" class="wp-caption alignleft" style="width: 778px"><img class="size-full wp-image-642" title="WebKit inspector's resources panel" src="http://blog.trasatti.it/wp-content/uploads/2012/10/inspector-resources-panel.png" alt="" width="768" height="601" /><p class="wp-caption-text">WebKit inspector&#8217;s resources panel, taken from https://www.webkit.org/blog/197/web-inspector-redesign/</p></div>
<p>The Navigation Timing API is a first step in this direction. In the past you would have used <code>Date.now()</code> to measure the interval of time between two events, but with the Navigation Timing API you get access to the full timing information related to the page, from when the browser opened the connection to when it resolved the DNS name to when it finished loading the page. All in milliseconds. I should clarify that the Navigation Timing API gives you information about the entire page, not each resource that composes it.</p>
<h2>How to measure the page speed?</h2>
<p>I found a lot of great articles about the Navigation Timing API and a couple of examples that really caught my eye, but I did not find an example that I could really copy and paste, so I thought I&#8217;d create one. Check it out at <a href="http://logme.mobi/jsnt/index.php">http://logme.mobi/jsnt/index.php</a></p>
<p>My example is quite simple, load a basic HTML page with some text and an image and record how long it takes to load. There are few things to note. First of all my code is VERY simple, I wanted it to be this simple, this way it&#8217;s a lot easier for you to read it and copy what you need. It&#8217;s all in one file, making it dead easy to see all the piece.</p>
<p>The Navigation Timing API introduces a new attribute, <code>window.performance</code>, which hosts 2 more attributes called <code>timing</code> and <code>navigation</code>. <code>timing</code> holds timing information about the loading of the page and <code>navigation</code> holds information about the actual HTTP request performed, i.e. if it navigated there (clicked on a link or the user entered the URL), if it&#8217;s a reload or a history traversal, going either back or forward. Simple.</p>
<p>Let&#8217;s start with the good news, all three major desktop browsers support the unprefixed attribute, <code>window.performance</code>. If you wanted to support older versions of Chrome or IE9 beta you must use respectively <code>webkitPerformance</code> and <code>msPerformance</code> (I did not find any references of <code>mozPerformance</code> on MDN, so I assume Mozilla went straight to the unprefixed version). On mobile the API is supported, unprefixed, on IE9 and higher, Android 4 and Chrome on Android. It is not supported on any version of iOS up to 6. Unless you have a very good reason for this, it is safe to stick to the standard, but just in case you wanted, I have written a simple check in my script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">featureDetect.<span style="color: #660066;">supported</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">msPerformance</span> 
   <span style="color: #339933;">||</span> window.<span style="color: #660066;">webkitPerformance</span> <span style="color: #339933;">||</span> window.<span style="color: #660066;">performance</span>
   <span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
&nbsp;
featureDetect.<span style="color: #660066;">unprefixed</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">performance</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>featureDetect.<span style="color: #660066;">unprefixed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> window.<span style="color: #660066;">performance</span>.<span style="color: #660066;">timing</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>featureDetect.<span style="color: #660066;">prefixed</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;ms&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> window.<span style="color: #660066;">msPerformance</span>.<span style="color: #660066;">timing</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>featureDetect.<span style="color: #660066;">prefixed</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;webkit&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> window.<span style="color: #660066;">webkitPerformance</span>.<span style="color: #660066;">timing</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
  alert<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Unexpected error while fetching navigation timing data.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The main action happens in <code>printIt()</code>, there I look at the <code>window.performance.timing</code> array and loop through each value to calculate the time each step took. I use the <code>order</code> array to order the different steps. Depending on what you are measuring you might want to look at different parts of the load process. For example you might have heard Steve Souders recommending that you <a title="High Performance Web Sites: Rule 11 – Avoid Redirects" href="http://developer.yahoo.com/blogs/ydn/posts/2007/07/high_performanc_9/">avoid redirects</a>, but then we all see how Twitter, Facebook and Google send us through one if not more redirects to follow a link. How much do those cost? If there was in fact a redirect the <code>timing</code> attribute will contain the <code>redirectStart</code> and <code>redirectEnd</code> values. The URL I provided earlier is a tiny PHP script that redirects the browser to a static page, for me, the redirect takes about 340ms, i.e. a third of the total load time, that&#8217;s 1/3 of the time wasted.</p>
<p>You now have an idea of the information that you can collect with the Navigation Timing API. Microsoft has a more complete example that also gives you a sense of how a page gets slower as you add resources, <a title="Navigation timing" href="http://ie.microsoft.com/testdrive/Performance/msPerformance/Default.html?loaded=0">Navigation timing</a> (although it is designed to be cross-browser, when I tried with Chrome 22 and 23 it did not run correctly, works fine with Firefox and IE).</p>
<h2>Can I debug from my PC?</h2>
<p>The short answer is &#8220;nearly&#8221;. You can enable the remote debugger on Chrome for Android or use Visual Studio for Windows Phone and dump data from the <code>window.performance.timing</code> array. For the standard Android browser, you still have to rely on something <a title="weinre" href="http://people.apache.org/~pmuellr/weinre/docs/latest/">weinre</a>.<br />
If you wanted to collect information on a server for statistical purposes you could build your own format or you could use HAR; either way you will need a server to collect the information.</p>
<h2>What else?</h2>
<p>There are two other specs that are very much complementary to the Navigation API, the <a title="Performance Timeline" href="http://www.w3.org/TR/performance-timeline/">Performance Timeline</a> and <a title="Resource Timing" href="http://www.w3.org/TR/resource-timing/">Resource timing</a>. In short, the first one lets you see in which order each resource has been loaded by the browser and the second one lets you access detailed loading information of each resource. While the Navigation timing API gives you an overview of the whole page load, you might want to know how long each image or each external script took to load. These specs are already in very good shape, so far IE10 is the only one to implement them with Chrome coming soon. I will cover these in another article very soon.<br />
If you have followed recent trends in Web design you will understand why these API&#8217;s will be very helpful. Think of responsive Web design where some resources are loaded selectively, it can be hard understanding exactly why your page is slow unless you can see exactly what happens and when. If you are relying on external resources (like Google analytics or a facebook button) you might want to avoid loading them if there is too much network latency. IE9 and later already implement a property called <code>msFirstPaint</code> that tells you when the document began to be displayed. Chrome already implements the <code>memory</code> property that gives access to JavaScript memory usage data and the Web performance WG is working on a spec.</p>
<h3>Wait! Where&#8217;s the code?</h3>
<p>I could have setup a repository for my example, but honestly, it&#8217;s so small that you can just go ahead, right-click and save it.</p>
<h2>Read more</h2>
<p>I did a lot of reading before I wrote this article, these are some of the useful resources that I collected:</p>
<ul>
<li>W3C&#8217;s <a title="Web Performance publications" href="http://www.w3.org/wiki/Web_Performance/Publications">Web performance WG publications</a> (see all the specs the group is working on and their status)
<ul>
<li><a title="Navigation timing" href="http://www.w3.org/TR/navigation-timing/">Navigation Timing</a> (PR as of 26 Jul 2012)</li>
<li><a title="High resolution time" href="http://www.w3.org/TR/hr-time/">High Resolution Time</a> (PR as of 23 Oct 2012)</li>
<li><a title="Resource timing" href="http://www.w3.org/TR/resource-timing/">Resource Timing</a> (CR as of May 2012)</li>
</ul>
</li>
<li>Microsoft has some excellent documentation on <a title="MSDN Web Performance" href="http://msdn.microsoft.com/en-us/library/ie/hh673556(v=vs.85).aspx">Performance</a> and <a title="MSDN Timing and Performance API's" href="http://msdn.microsoft.com/library/ie/hh772738.aspx">Timing</a> API&#8217;s for IE9 and IE10</li>
<li>Yottaa&#8217;s site <a href="http://www.yottaa.com/">Website assessment</a>, link on homepage</li>
<li><a title="Mobitest" href="http://mobitest.akamai.com/m/index.cgi">Mobitest</a> by Akamai, formerly Blaze.io</li>
<li><a title="Measuring page load speed with Navigation timing @ html5 rocks" href="http://www.html5rocks.com/en/tutorials/webperformance/basics/">Measuring page load speed with Navigation timing</a> @ html5 rocks, look at the nice breakdown of each event and the order in which they happen</li>
<li>Kasia wrote a bookmarklet that shows the page speed in a waterfall style similar to WebKit Web inspector, code available on GitHub: <a title="Breaking down onLoad" href="http://kaaes.github.com/timing/">Breaking down onLoad</a></li>
<li><a title="HAR Viewer" href="http://www.softwareishard.com/har/viewer/">HAR online Viewer</a> and other <a title="HAR Adopters" href="http://www.softwareishard.com/blog/har-adopters/">HAR adopters</a></li>
<li>More about <a href="http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting">feature detection</a> and <a title="Modernizr" href="http://modernizr.com/">Modernizr</a>, the feature detection library</li>
</ul>
<p>This article is cross-posted on Nokia Developer&#8217;s site at <a href="http://www.developer.nokia.com/Blogs/Code/2012/11/19/measuring-site-performance-with-javascript-on-mobile/">Measuring site performance with JavaScript on mobile</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2012/11/measuring-site-performance-with-javascript-on-mobile.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HTML5 forms (and IE10 (Mobile))</title>
		<link>http://blog.trasatti.it/2012/11/html5-forms-and-ie10-mobile.html</link>
		<comments>http://blog.trasatti.it/2012/11/html5-forms-and-ie10-mobile.html#comments</comments>
		<pubDate>Wed, 07 Nov 2012 23:20:20 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[Nokia]]></category>
		<category><![CDATA[nokia_dev]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=630</guid>
		<description><![CDATA[One of the many improvements introduced by HTML5 is around forms, users hate filling forms and developers hate validating the data submitted. HTML5 makes these tasks a lot simpler. In this article I will not talk about what HTML5 added, but I will rather focus on what is new in IE10 mobile, i.e. the browser that comes [...]]]></description>
				<content:encoded><![CDATA[<p>One of the many improvements introduced by HTML5 is around forms, users hate filling forms and developers hate validating the data submitted. HTML5 makes these tasks a lot simpler.<br />
In this article I will not talk about what HTML5 added, but I will rather focus on what is new in IE10 mobile, i.e. the browser that comes with Windows Phone 8. At the end of the article I have collected a few useful links that cover HTML5 forms at large and provide more examples and complete support tables. All the code examples are meant to be cross-browser, unless specified.<span id="more-630"></span></p>
<h2>What&#8217;s new in IE10</h2>
<p>IE10 and IE10 mobile are substantially the same browser. In I will try to highlight some different behaviors often determined by the different hardware configurations and environments. To give you an idea consider the input element, it now supports a new state for the type attribute: &#8220;number&#8221;; if you are using a PC with a full keyboard you will not see any difference, but if you are using a device like the Lumia 920 with a virtual keyboard, that keyboard will only show you numbers. Try using the &#8220;tel&#8221; state and the keyboard will show numbers, the plus sign, the dash and the space. These simple enhancements will make the life of your users a lot easier. This different behavior in different environments is true for pretty much all browsers and all OS&#8217;s.</p>
<p>As of today, IE10 implements most of the HTML5 spec related to <a title="W3C HTML5 forms" href="http://www.w3.org/TR/html5/forms.html">forms</a> and in fairness none of the current browsers covers 100% of the spec. The good news is that all modern browsers have wide coverage and they all degrade gracefully when something is not yet supported.</p>
<h2>What doesn&#8217;t work</h2>
<p>As mentioned there are a few things that are not yet implemented and I suggest you check <a title="can I use | HTML5 forms" href="http://caniuse.com/#feat=forms">can I use</a> for more details on cross-browser support and look at the official <a title="HTML5 forms" href="http://msdn.microsoft.com/en-us/library/ie/hh673544(v=vs.85).aspx">Microsoft documentation</a> for the specifics of IE10.<br />
Although IE10 supports most of the improvements to forms it does not support the <code>output</code> element, Microsoft doesn&#8217;t clearly state if it supports it or not, so I thought I would clarify. <a title="Custom validation error messages" href="http://msdn.microsoft.com/en-us/library/ie/hh673544(v=vs.85).aspx#custom_validation_error_messages">Custom validation error</a> messages are supported in Windows 8, but not on mobile. Custom validation error messages are not supported in iOS 6 or Safari 6. Similarly, the datalist element works in Windows 8, but not on Windows Phone 8.<br />
HTML5 defines a number of new properties for the input element such as <code>valueAsNumber</code>, <code>stepUp</code> and <code>stepDown</code>, Microsoft&#8217;s <a title="HTMLInputElement documentation" href="http://msdn.microsoft.com/en-us/library/ie/hh869710(v=vs.85).aspx">documentation</a> says they are supported, but I could not get any of these to work on either Windows 8 or WP8.<br />
Either way, there is no reason for you not to use it as it degrades gracefully and we can expect that it will be implemented at some point.</p>
<p><strong>Update:</strong> The <code>stepUp</code> and <code>stepDown</code> methods actually work when the input type state is &#8220;range&#8221;.</p>
<h3>How does it compare to other mobile OS&#8217;s?</h3>
<p>Here is a quick summary table of the features that are not consistent across different OS&#8217;s. I recommend that you look on <a href="http://caniuse.com/#feat=forms">can I use</a> for more details and of course always test on real devices.</p>
<table>
<thead>
<tr>
<th>Feature</th>
<th>IE10 on WP8</th>
<th>IE10 on Win8</th>
<th>iOS5 &amp; 6</th>
<th>Android 4.1.1</th>
<th>Chrome 18 on Android</th>
</tr>
</thead>
<tbody>
<tr>
<td>Date</td>
<td>NO</td>
<td>NO</td>
<td>YES</td>
<td>NO</td>
<td>YES</td>
</tr>
<tr>
<td>Progress</td>
<td>YES</td>
<td>YES</td>
<td>NO</td>
<td>NO</td>
<td>YES</td>
</tr>
<tr>
<td>Output</td>
<td>NO</td>
<td>NO</td>
<td>YES</td>
<td>YES</td>
<td>YES</td>
</tr>
<tr>
<td>Datalist</td>
<td>NO</td>
<td>YES</td>
<td>NO</td>
<td>NO</td>
<td> NO</td>
</tr>
<tr>
<td>Custom error</td>
<td>NO</td>
<td>YES</td>
<td>NO</td>
<td>NO</td>
<td>YES</td>
</tr>
<tr>
<td>valueAsNumber</td>
<td>NO</td>
<td>NO</td>
<td>YES</td>
<td>YES</td>
<td>YES</td>
</tr>
<tr>
<td>stepUp and stepDown</td>
<td>NO</td>
<td>NO</td>
<td>YES</td>
<td>YES</td>
<td>YES</td>
</tr>
</tbody>
</table>
<h2>A real world example</h2>
<p>I built a simple form covering some of the new features of HTML5 forms. First of all I wanted to show how the new elements and attributes behave in IE10 mobile and how some gracefully degrade. This is how it looks like in Chome 22 (probably the most complete implementation today) and how it looks like on a Lumia 920.</p>
<div id="attachment_687" class="wp-caption alignnone" style="width: 352px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/11/Screen-Shot-2012-11-06-at-4.53.15-PM.png"><img class="size-full wp-image-687" title="Chrome 22 showing form.html" src="http://blog.trasatti.it/wp-content/uploads/2012/11/Screen-Shot-2012-11-06-at-4.53.15-PM.png" alt="Chrome 22 screenshot of form.html" width="342" height="649" /></a><p class="wp-caption-text">Chrome 22</p></div>
<div id="attachment_689" class="wp-caption alignnone" style="width: 394px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/11/WP8_formpage.png"><img class="size-full wp-image-689" title="WP8 screenshot of form.html" src="http://blog.trasatti.it/wp-content/uploads/2012/11/WP8_formpage.png" alt="Screenshot of form.html taken with a Lumia 920 running Windows Phone 8" width="384" height="1024" /></a><p class="wp-caption-text">Windows Phone 8 on Lumia 920 (2 screenshots merged to show the entire page)</p></div>
<p>You can try it yourself at <a title="HTML5 form example" href="http://logme.mobi/html5/form.html">http://logme.mobi/html5/form.html</a>. Look at the code and feel free to take what you need, but don&#8217;t expect accurate error checking and validation unless it&#8217;s specifically useful for this article.</p>
<p>As you can see the placeholder texts are there, some fields are surrounded with a red glow and some with a green one, these are defined in CSS using pseudo classes for <a title="Pseudo-class :required | MDN" href="https://developer.mozilla.org/en-US/docs/CSS/:required">required</a> and optional fields. You might have noticed that Chrome shows a placeholder for the birthday field, that&#8217;s because the browser correctly interprets the &#8220;date&#8221; state for the type attribute of the input element, but on IE10 mobile this field is treated like a normal text field (the expected graceful degradation).<br />
This is how I defined the input field for the name:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;name&quot;</span> name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;name&quot;</span> placeholder<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;John Doe&quot;</span> required<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>And this is how I defined the input field for the birthday:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;date&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;bday&quot;</span> name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;bday&quot;</span><span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>And my pseudo-class for the required fields, notice that I still defined the prefixed versions, mostly for mobile (read more about <a title="can I use | box-shadow" href="http://caniuse.com/css-boxshadow">box-shadow support on can I use</a>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #3333ff;">:required </span><span style="color: #00AA00;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#88a</span><span style="color: #00AA00;">;</span>
 -webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> .5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 -moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> .5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 -o-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> .5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 -ms-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> .5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">15px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> .5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>If you use a lot Chrome or Safari you might be familiar with the little widget on the far right of the &#8220;Donation&#8221; field. As I was writing my example and testing I quite liked the functionality of it. When testing on IE10 and later checking the spec I realized that this is an extra that Chrome adds. HTML5 adds instead two new methods of the &#8220;input&#8221; element named <code>stepUp</code> and <code>stepDown</code> and the developer is left with the burden to implement it, but also the freedom of designing it as he wishes. Either way all browsers evaluate the value correctly. Since I define a &#8220;min&#8221; and a &#8220;step&#8221;, the value will be considered <strong>invalid</strong> until the user enters a multiple of 10. If you test on your Windows Phone 8 device you will see that the surrounding color will change from red to green if you enter for example the number 20. Look at the source code to see the CSS pseudo-classes. This is the markup I used to define the input field:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;number&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;donation&quot;</span> name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;donation&quot;</span> required 
  min<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;10&quot;</span> step<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;10&quot;</span> title<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Type the amount, only multiples of 10&quot;</span>
  oninput<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;test_output.value=donation.valueAsNumber+10&quot;</span><span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Chrome 22 on Mac:</p>
<div id="attachment_655" class="wp-caption alignnone" style="width: 369px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/10/stepUIChrome.png"><img class="size-full wp-image-655" title="step UI in Chrome" src="http://blog.trasatti.it/wp-content/uploads/2012/10/stepUIChrome.png" alt="image shows how &quot;step&quot; is implemented in Chrome" width="359" height="38" /></a><p class="wp-caption-text">See the little arrows on the right of the input field that automatically increment or decrement the value based on the value of the step attribute</p></div>
<p>IE10 mobile on a Lumia 920:</p>
<div id="attachment_693" class="wp-caption alignnone" style="width: 586px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/11/WP8_step.png"><img class="size-full wp-image-693" title="WP8 input step" src="http://blog.trasatti.it/wp-content/uploads/2012/11/WP8_step.png" alt="IE10 validate the correctly the value and does not add any widget for the step attribute" width="576" height="137" /></a><p class="wp-caption-text">Value correctly evaluated according to the input attributes and no extra widget added</p></div>
<p>Creating a widget to handle the stepping is very simple. Below is an example I wrote using two buttons and a JavaScript function that invokes the <code>.stepUp(n)</code> and <code>.stepDown(n)</code> methods where &#8220;n&#8221; is the number of steps you want to increment or decrement the value of the field:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;number&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;donation&quot;</span> name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;donation&quot;</span> required min<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0&quot;</span> 
  step<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;2&quot;</span> title<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Enter an even number between 0 and 10&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>button type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;stepUp&quot;</span> name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;stepUp&quot;</span> 
onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;step('up')&quot;</span><span style="color: #339933;">&gt;</span>Add <span style="color: #CC0000;">10</span><span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>button type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;stepDown&quot;</span> name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;stepDown&quot;</span> 
onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;step('down')&quot;</span><span style="color: #339933;">&gt;</span>Subtract <span style="color: #CC0000;">10</span><span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000066; font-weight: bold;">function</span> step<span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> donation <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'donation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    min <span style="color: #339933;">=</span> donation.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'min'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>donation.<span style="color: #660066;">valueAsNumber</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    donation.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> min<span style="color: #339933;">;</span>    <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// the actual stepping up or down, 1 is the number of steps</span>
  <span style="color: #009900;">&#40;</span>action<span style="color: #339933;">==</span><span style="color: #3366CC;">'up'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> donation.<span style="color: #660066;">stepUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> donation.<span style="color: #660066;">stepDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>As you can see I used <a title="W3C Common input element APIs" href="http://www.w3.org/TR/html5/common-input-element-apis.html#common-input-element-apis">valueAsNumber</a> in both example. This is another handy addition of HTML5, unfortunately I could not get it to work in IE10, of course you can always use <code>.value</code>.</p>
<p>Next I want to show the &#8220;progress&#8221; element, in this example I used a very simple JavaScript function to change the value attribute of the progress element and hence change the look of the bar based on how many fields the user has filled.</p>
<p>I did not go into the detail of verifying if the values are valid, it&#8217;s really just to show how the browser animates the bar. You can use the CSS3 property &#8220;animation-name&#8221; to switch between the default (a bar) and a ring. This is the HTML:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>progress id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;progBar&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0&quot;</span> max<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;100&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">%&lt;/</span>progress<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Input type states like email, number and tel affect the virtual keyboard layout. As you would expect the keyboard for email is the standard virtual keyboard with the &#8220;@&#8221; symbol immediately available, on the other hand, using the &#8220;number&#8221; type a keypad is displayed and using the &#8220;tel&#8221; type a keypad with digits, the plus sign, space and dash are displayed. Very handy, see the screenshots here:</p>
<div id="attachment_694" class="wp-caption alignnone" style="width: 394px"><a href="http://blog.trasatti.it/wp-content/uploads/2012/11/WP8_phonenumber.png"><img class="size-full wp-image-694" title="WP8 phone keypad" src="http://blog.trasatti.it/wp-content/uploads/2012/11/WP8_phonenumber.png" alt="WP8 shows a keyboard optimized for phone numbers" width="384" height="640" /></a><p class="wp-caption-text">WP8 shows a keyboard to enter phone numbers</p></div>
<p>You might also have noticed the little JavaScript that is executed in the &#8220;donation&#8221; <code>input</code> field, if the browser supports it it will update the value of the <code>output</code> element. In IE10 it degrades gracefully and always shows the default value.</p>
<h2>Continue reading</h2>
<p>This article covers most of the new implementations in IE10, but not everything. I have collected more resources that I think are very valuable, if you haven&#8217;t read them yet, I strongly suggest you do it now.</p>
<ul>
<li><a title="Making forms fabulous with HTML5" href="http://www.html5rocks.com/en/tutorials/forms/html5forms/">Making forms fabulous with HTML5</a> by Jan Kleinert</li>
<li><a title="A form of madness" href="http://diveintohtml5.info/forms.html">A form of madness</a> by Mark Pilgrim as part of Dive into HTML5
<ul>
<li><a title="Form validation" href="http://diveintohtml5.info/forms.html#validation">HTML5 form validation</a></li>
</ul>
</li>
<li>PPK&#8217;s &#8220;<a title="HTML5 tests - inputs" href="http://www.quirksmode.org/html5/inputs.html">HTML5 tests &#8211; inputs</a>&#8220;, i.e. support table</li>
<li>For cross-browser support information, check out the always great <a title="can I use | forms" href="http://caniuse.com/#feat=forms">can I use</a></li>
<li><a title="The current state of HTML5 forms" href="http://wufoo.com/html5/">The current state of HTML5 forms</a> @ wufoo</li>
</ul>
<p>Microsoft has a lot of documentation specific for IE10, I found these articles particularly useful:</p>
<ul>
<li><a title="Forms" href="http://msdn.microsoft.com/en-us/library/ie/hh673544(v=vs.85).aspx">HTML5 forms</a>
<ul>
<li><a title="Progress element" href="http://msdn.microsoft.com/library/ie/hh772953.aspx">Progress element</a></li>
</ul>
</li>
<li>A very complete <a title="HTML5 forms" href="http://ie.microsoft.com/testdrive/HTML5/Forms/default.html">example</a> of what is supported in IE10</li>
<li><a title="HTML5 form controls sample" href="http://code.msdn.microsoft.com/ie/Form-controls-part-1-abae6a9e">Download</a> the full source code of a forms controls sample</li>
<li><a title="CSS3 animations" href="http://msdn.microsoft.com/en-us/library/ie/hh771874(v=vs.85).aspx">CSS3 animations</a> in IE10</li>
</ul>
<p><strong> This article is <a href="http://www.developer.nokia.com/Blogs/Code/2012/11/09/html5-forms-and-ie10-mobile/">cross-posted</a> on Nokia Developer.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2012/11/html5-forms-and-ie10-mobile.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobilewood 2</title>
		<link>http://blog.trasatti.it/2012/06/mobilewood-2.html</link>
		<comments>http://blog.trasatti.it/2012/06/mobilewood-2.html#comments</comments>
		<pubDate>Tue, 19 Jun 2012 01:25:44 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Future Friendly]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Mobilewood]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=613</guid>
		<description><![CDATA[About nine months ago a few of the speakers participating to BDConf in Nashville decided to get together for a few days and try to think about mobile, the Web and the challenges that companies, developers and designers face every day. Some of them blogged about it right away (Mobilewood, Future Friendly at Mobilewood). Organizing [...]]]></description>
				<content:encoded><![CDATA[<p>About nine months ago a few of the speakers participating to <a title="Breaking Development Nashville 2011" href="http://bdconf.com/2011/nashville">BDConf</a> in Nashville decided to get together for a few days and try to think about mobile, the Web and the challenges that companies, developers and designers face every day. Some of them blogged about it right away (<a title="Adactio: Mobilewood" href="http://adactio.com/journal/4873/">Mobilewood</a>, <a title="Future Friendly at Mobilewood" href="http://globalmoxie.com/blog/future-friendly-mobilewood.shtml">Future Friendly at Mobilewood</a>).<span id="more-613"></span></p>
<h2>Organizing the event</h2>
<p>It was still cold and snowy in New England, but some of the original participants of Mobilewood thought it would be great to meet in this area in Spring. Although only ten people participated in the first edition of Mobilewood they wanted to open the discussion to more people, get more thinking and more ideas and build on the concepts that were defined the first time. Since I moved to Boston in February it was very easy for me to immediately say <strong>YES</strong> to the invitation to Mobilewood 2.</p>
<p><a title="Globalmoxie" href="http://twitter.com/globalmoxie">Josh Clark</a> did an amazing job scouting rental properties and found the perfect place in <a href="https://maps.google.com/maps?q=Truro,+MA&amp;hl=en&amp;sll=37.0625,-95.677068&amp;sspn=43.578243,76.113281&amp;hnear=Truro,+Barnstable,+Massachusetts&amp;t=m&amp;z=12">Truro, MA</a>, at the top of Cape Cod, surrounded by the <a href="http://www.nps.gov/caco/">Cape Cod National seashore</a> park.</p>
<div class="wp-caption alignnone" style="width: 630px"><a href="http://www.flickr.com/photos/andreatrasatti/7401476288"><img class=" " title="Indoor pool @ Mobilewood 2" src="http://farm8.staticflickr.com/7235/7401476288_c61552b383_z.jpg" alt="Indoor pool @ Mobilewood 2" width="620" height="406" /></a><p class="wp-caption-text">Indoor pool in the Mobilewood 2 mansion</p></div>
<p>This time around nine of us made it to the work retreat. The plan was to arrive on Thursday afternoon and leave on Sunday. While <a href="http://scottjehl.com/">Scott Jehl</a> and I are local, most of the others were traveling from all over the US. We all knew each other either from previous conferences or because of previous work, yet we thought it would help to introduce ourselves he first evening. We talked about what keeps us up at night both in work and in real life, that would be the starting point for our work. We gave ourselves a night to think and the day after the real work started.</p>
<h2>Moving the Future Friendly thinking ahead</h2>
<p>Friday morning we got all our ideas on the wall, sorted them, grouped them and decided what we wanted to achieve during the weekend. When you have so many brilliant people in one place you want to reach for the moon, but time is incredibly precious and you have a clear deadline of about 48 hours. We had to be laser focused.</p>
<p>We split in three groups and started thinking about how can get more people to embrace the Future Friendly values, how we can help them and how they can help others.<br />
We agreed that responsive Web design has evolved to a stage where you can create a good Web site or app applying the main principles, but that it&#8217;s still very hard, so we wanted to dedicate some time to think about what can be done better and more easily. Trying to look further ahead, we tried to imagine what is coming for the Internet and the Web in the next few years and what we can do, as the creators of Web contents to influence that future.</p>
<h2>Come aboard</h2>
<p>It was nearly impossible to cover all the topics we set for ourselves and that is OK with this type of meeting. You want to set some goals, but you also want leave space for improv and see what happens. We all agreed that the main goal of Future Friendly is to spread the word, in a way educate on how we can all create better content for the Web that works well on all sorts of devices. The more people read, learn and practice the principles the better it will get. We defined many steps that will help this happen, but we also tried to distill the most important elements. The result is a new page on the Future Friendly site titled &#8220;<a title="Future Friendly - Come aboard" href="http://futurefriend.ly/come-aboard.html">Come aboard</a>&#8220;. If you don&#8217;t already know the site I recommend that you go and check it out now, if you already know it, see the new section.</p>
<p>The biggest take-away for me regarding the community engagement is that techniques evolve and then become deprecated quickly, but the thinking lasts long and that is what we want to do with the Future Friendly thinking.</p>
<h2>Future of the Web</h2>
<p>As geeks that carry all sorts of devices with us it was easy to agree that Internet and the Web are becoming pervasive. The technologies that were created to deliver Web pages are now used for much more such as audio, video and raw data (think about REST APIs that use HTTP as a transport, but show data such as your tweet or your open graph). We think that these are the foundations for a new set of devices, some of which will consume this data, some will display it, some will produce it and some will do both. Think about the <a title="Nest" href="http://www.nest.com">Nest thermostat</a> that controls the temperature in your house, but can be controlled via a Web site or an app on your phone. Think about the upcoming <a title="Leap motion" href="http://www.leapmotion.com">Leap motion</a> that will let you control your computer waving your hands and pointing. Then imagine a future where multiple devices will cooperate, for example imagine having a Web browser on your TV, you will say &#8220;TV, open the Boston Globe site&#8221; and the TV will show the site, but then&#8230; How will you tell the TV which article to open? How will the browser know which link you mean? Now think about building the Web of the future, it is already complicated with click and touch events, think of adding &#8220;voice&#8221; events and you get the idea. Now think about the Kinect it&#8217;s an additional device that allows me to use my body and my hands to control what is basically a computer. What if many devices could interact with each other, each could offer certain inputs and outputs depending on what it is. A mobile phone with a touch screen can be used as a trackpad, the screen can be used to display the temperature of the fridge or the time until your cake is baked. Before this can happen and be useable some innovation needs to happen in the browser and of course in Web apps. We think we can and should influence some of the upcoming technologies.</p>
<h2>We are geeks</h2>
<p>As you would expect we all had our computers and various devices at hand. You might need some testing right?</p>
<div class="wp-caption alignnone" style="width: 630px"><a href="http://www.flickr.com/photos/lyza/7382241542"><img class=" " title="Mobilewood 2 devices" src="http://farm6.staticflickr.com/5271/7382241542_b94c12e9d5_z.jpg" alt="This is a collection of all the computers and mobile devices we brought at Mobilewood 2" width="620" height="407" /></a><p class="wp-caption-text">Mobilewood 2 devices</p></div>
<p>&nbsp;</p>
<h2>The Mobilewood 2 gang</h2>
<p>This is us trying to be serious&#8230; or not.</p>
<div class="wp-caption alignnone" style="width: 630px"><a href="http://www.flickr.com/photos/lukew/7382466738"><img class=" " title="Mobilewood 2" src="http://farm8.staticflickr.com/7102/7382466738_26b079932e_z.jpg" alt="A group picture of the participants of Mobilewood 2" width="620" height="427" /></a><p class="wp-caption-text">Group photo of Mobilewood 2</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2012/06/mobilewood-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Responsive images and tinySrc</title>
		<link>http://blog.trasatti.it/2011/05/responsive-images-and-tinysrc.html</link>
		<comments>http://blog.trasatti.it/2011/05/responsive-images-and-tinysrc.html#comments</comments>
		<pubDate>Sun, 29 May 2011 16:36:29 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[Responsive design]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Mobile]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=603</guid>
		<description><![CDATA[Producing images of the perfect size, when you create a Web site that targets multiple device classes with very different screen sizes is always a problem. There are a number of solutions out there, but they all require some kind of server-side detection and image wrangling. tinySrc is a nice and simple solution that takes [...]]]></description>
				<content:encoded><![CDATA[<p>Producing images of the perfect size, when you create a Web site that targets multiple device classes with very different screen sizes is always a problem. There are a number of solutions out there, but they all require some kind of server-side detection and image wrangling. <a title="tinySrc" href="http://tinysrc.net/">tinySrc</a> is a nice and simple solution that takes away most if not all of the legwork. Possibly the only downside of tinySrc is that it relies on server-side detection itself. A lot of developers that worked with browsers like Chrome, Firefox and Opera advocate for client-side detection where it&#8217;s the browser that tells you about its capabilities instead of relying on a static database. I will not go into the details of why and when one is better than the other, let&#8217;s just say that tinySrc already gives you the power of the server-side, with my little software you can also benefit from the power of the client.<span id="more-603"></span></p>
<p><span style="line-height: 35px; font-size: 23px; color: #000000;">Just give me the solution</span></p>
<p>If all you care is a super-simple solution that gets the job done, I recommend that you use tinySrc in its basic configuration. tinySrc does a lot of legwork for you and the resulting images are in 90% of the cases or more just great. Check out the <a title="tinySrc" href="http://tinysrc.net/">tinySrc</a> home and you already have all you need.</p>
<h2>So why mix tinySrc with a JavaScript?</h2>
<p>At <a href="http://mobilism.nl/2011">mobilism</a> I met <a href="http://www.scottjehl.com/">Scott Jehl</a> for the first time and he mentioned working on a JavaScript that would take care of providing the right images based on client-side detection. It sounded quite interesting to me because most of the times, in order to create a decent <a href="http://www.alistapart.com/articles/responsive-web-design/">responsive design</a>, you have to create all the media files in advance.</p>
<p>I started looking at his <a href="https://github.com/filamentgroup/Responsive-Images">Responsive Images</a> library and liked the idea. We exchanged a few messages and it seemed easy enough. What it does not do is what I know is very often the real issue: generate the images. So it taps into the power of the client-side detection to understand what the browser and device can do, but then relies on media files generated in advance. In Filament&#8217;s online <a href="http://filamentgroup.com/examples/responsive-images/">demo</a> you can see that Scott generated 2 images, small and big and that&#8217;s all you get. Of course you can extend the JavaScript to manage more sizes, but every time you add a format you will have to edit your JavaScript. This is a good start, but not exactly what I was looking for.</p>
<p>I also thought about <a href="http://wordpress.org/extend/plugins/wordpress-mobile-pack/">WordPress Mobile Pack</a> and users that are on simple hosting plans or maybe don&#8217;t have the time and skills to generate all the images in the right formats. tinySrc seemed a perfect match.</p>
<h2>How it works</h2>
<p>The changes I made to Scott&#8217;s JavaScript and Rewrite rules are very limited, but I think they open the door to some substantial benefits. The JavaScript now reads the available width and height of the screen and passes those values to tinySrc so that an image of the perfect size will be generated (I padded the image of 20px for safety). You still need to have a small image (for fallback purposes) and a full-size image so that tinySrc has a high resolution image to work from (of course the bigger the better).</p>
<p><a href="http://ri.logme.mobi">See it</a> in action.</p>
<h2>Why use it?</h2>
<p>If you want to apply responsive design you must create the correct media files for each target device or family. This little script allows you to do that with near-zero effort. If you want to support device families tinySrc supports that, but you will have to change the JavaScript. What&#8217;s not to love?</p>
<h2>Why NOT use it?</h2>
<p>The JavaScript works so that it parses your HTML and replaces all image URLs with a dummy URL on your Apache server (at the time of writing the script requires Apache, nginx in the works). When the client requests that URL your Apache server will redirect the client to tinySrc. This is at least 1 HTTP request for every image that we might avoid. tinySrc on its own already does a great job, so this really is a step further toward responsive design. The only one that knows which approach is best is probably you.</p>
<h2>What next?</h2>
<p>I am looking at a couple more improvements, one idea is to use tinySrc&#8217;s dataURI API call and use that to replace all image URLs. That should save all the requests to your Apache server that are then redirected to tinySrc. Depending on how many images you have this might or might not make a difference. The problem is browser support, I am looking for some data. If you have any, please contact me.</p>
<h2>The source code</h2>
<p>If you like what you saw you can get the code on <a href="https://github.com/atrasatti/Responsive-Images/commit/30ebc7a82f4e49ac95dee50b00cf9dc645e8bfbb">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2011/05/responsive-images-and-tinysrc.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why Microsoft and Windows Phone 7 is the best way to pee in your pants</title>
		<link>http://blog.trasatti.it/2011/02/why-microsoft-and-windows-phone-7-is-the-best-way-to-pee-in-your-pants.html</link>
		<comments>http://blog.trasatti.it/2011/02/why-microsoft-and-windows-phone-7-is-the-best-way-to-pee-in-your-pants.html#comments</comments>
		<pubDate>Mon, 14 Feb 2011 17:26:33 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[blackberry]]></category>
		<category><![CDATA[Forum Nokia]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Nokia]]></category>
		<category><![CDATA[Palm]]></category>
		<category><![CDATA[Symbian]]></category>
		<category><![CDATA[WebOS]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=588</guid>
		<description><![CDATA[DISCLAIMER: I work for Nokia, Forum Nokia. DISCLAIMER 2: What I am going to say here is exclusively my own thinking and analysis and based only on what is publicly known. I have no insight on why and how the decisions were made, no insight of any behind-doors-agreements, gossip or promises. What I am writing [...]]]></description>
				<content:encoded><![CDATA[<p><strong>DISCLAIMER</strong>: I work for Nokia, Forum Nokia.<br />
<strong>DISCLAIMER 2</strong>: What I am going to say here is exclusively my own thinking and analysis and based only on what is publicly known.<br />
I have no insight on why and how the decisions were made, no insight of any behind-doors-agreements, gossip or promises.<br />
What I am writing here is simply the result of my thinking based on what I have read and heard in the public announcements.<span id="more-588"></span></p>
<h1>The options</h1>
<h2>Symbian</h2>
<p>Symbian is an old operating system that was developed for pocket devices, what we once called <a href="http://en.wikipedia.org/wiki/Personal_information_manager">PIM</a>&#8216;s or <a href="http://en.wikipedia.org/wiki/Personal_digital_assistant">PDA</a>&#8216;s. It was designed for devices that had a keyboard or a keypad, that were low on CPU and battery.<br />
For these reasons Symbian is VERY efficient on battery and CPU. Most of the UI was crafted to work well with a keyboard and a joystick. You might not know it, but in your Nokia N8, designed to be entirely touch and with no hardware keyboard, you still have a lot of keyboard shortcuts that you will likely never use. The Nokia E7 that is finally reaching the shelves now has a lot of shortcuts that you can use with your qwerty keyboard.<br />
The N8, with a 680Mhz CPU, performs almost as well as most Android devices that use a 1Ghz or better CPU, because it&#8217;s highly optimised, but you will never know it, because the UI is too clunky (more on this later).</p>
<p>Unfortunately what users expect at the high-end, is not what Symbian can offer today. Many of us are used to recharging their mobile every evening, something that most Nokia customers don&#8217;t do. Modern high-end mobile devices are expected to be snappy, to have a great browser with device APIs and graphics hardware acceleration, support applications developed with a relatively high-level programming language that lets you create a decent application or game in a week or so.<br />
<strong>Symbian was not designed for this.</strong><br />
Symbian^3 has a much better UI than before, mostly designed to support touch, but still with a lot of legacy menus and interfaces. The programming language is C++, with a lot of quirks and strange libraries. This is the result of 10+ years of evolution in a direction that is not what was planned back then. If you know Symbian and C++ very well, your application will have a raw performance that most other OSs can dream of, but unfortunately it will take you 3 months to develop, and not 3 weeks.<br />
This is true for developers out there, but it is also true for Nokia. Despite how hard Nokia has tried to blow new life in Symbian, it failed because the development environment is just too complex.</p>
<p>Unfortunately for Symbian, its highly optimised environment has determined its demise.</p>
<h2>MeeGo</h2>
<p>MeeGo was developed from the positive experience of Maemo. Maemo was an experiment, but it showed a lot of strong points and a surprisingly vibrant community. MeeGo was built on the best intentions to bring a great new OS built for mobile devices of all types (netbooks, tablets, in-car entertainment, smart phones).<br />
Unfortunately it has not delivered in the time frame that was needed to Nokia not to lose too much market share. iOS and Android devices are selling well, too well to keep waiting. Apple has iPods, iPhones, iPads and appleTVs. Android has loads of mobile phones, is coming to the tablet world and has the Google TV.<br />
Nokia announced in 2010 that it would deliver at least one MeeGo device. Then very late in 2010 announced that it would arrive in 2011.<br />
So far, we haven&#8217;t seen anything.</p>
<p>MeeGo is still a great promise, but unfortunately Nokia needs to sell devices today in order to develop a better OS, apps and platform for tomorrow.</p>
<h2>WebOS</h2>
<p>WebOS, is in my opinion a great OS with a very interesting approach with Web technologies as its development platform. It&#8217;s a great idea, that hasn&#8217;t really delivered for Palm. HP seems to be betting really big on it with the recent announcement of some very interesting devices in all ranges. That is fantastic for WebOS and HP might be able to work around the operators selling directly to the thousands of medium and large enterprises that rely on them for their servers, networks, printers and computers. It will be a great synergy I&#8217;m sure.</p>
<p>What does that offer to Nokia? Well, Nokia might have embraced it, but was HP interested? Probably too busy developing its own devices and integration with all the other services. HP certainly has a grand plan and Nokia might have been a distraction more than a valuable partner.</p>
<h2>RIM with QNX</h2>
<p>Similarly to HP, RIM has a foot in the enterprise business and something also in the consumer business. It has completed some very interesting acquisitions such as Torch mobile (which resulted in a much better browser in their blackberry OS 6) and TAT. They announced the Playbook tablet (a little too early IMHO) and are busy trying to get QNX to work on their devices starting with the Playbook tablet and later on mobile devices.</p>
<p>Similarly to HP, RIM is probably too busy completing its plans, to be bothered with Nokia. Let&#8217;s not forget that Nokia can be a great partner, but will also come with some strong requirements and big personality. At the end of the day Nokia has the infrastructure and experience to sell millions of devices per day, it cannot settle with a partner that will not have time for it.</p>
<h2>Microsoft and Windows Phone 7</h2>
<p>Of all the mobile OS&#8217;s installed on devices that are on the market today Windows Phone 7 is the youngest and likely the one that still has to prove the most. It has a nice new UI, very consumer oriented and it has the Microsoft hat, so you can expect good integration with their enterprise products such as Office and Exchange.<br />
Yet, the browser is not great and while the development environment is the very well known .NET, it does not have a number of developers dedicated to this platform that can make their store very interesting.<br />
Microsoft has been able to convince LG and Samsung to produce mobile phones and that&#8217;s great, but the sales so far haven&#8217;t been amazing.</p>
<h2>Android</h2>
<p>Assuming that Apple was not keen on letting Nokia use iOS, Android would have been the most obvious choice. Android is the most mature &#8220;modern&#8221; mobile OS after iOS, has a good UI, the second best marketplace and a vibrant, growing community of developers. I imagine that the conversation between Google and Nokia went like this:<br />
<strong>Andy R.</strong>: &#8220;Hello Stephen, nice to see you. So you are interested in Android? Well, we think it&#8217;s great, we have a great OS, we have a fantastic UI and we have some of the best UI and UX expert in the world working to make it even better. Our developers love our open source attitude and love the Google cloud services. We have by far the best search engine, the biggest ad network and the best maps. You are welcome to take the source and run with it. What can you do for us?&#8221;<br />
<strong>Stephen E.</strong>: &#8220;Wait a second, <strong>WE </strong>have the best maps, ours are vector based and much faster to download, plus we can preload them&#8221;.<br />
<strong>Andy R.</strong>: &#8220;Stephen, we have vector maps as well, already deployed on Android 2.3 and even better in 3.0&#8243;.<br />
<em>Stephen E. stands up and walks out with a little teardrop.</em></p>
<h1>What Nokia has on the table</h1>
<p>So what could Nokia offer, as a partner, to these players that would make the cooperation more interesting for both? Nokia is by far the number one player in the low-end market and in most if not all developing countries. In India, China and South Africa Nokia is basically a monopolist. This is very cool and very good for Nokia&#8217;s cashflow, but not of great value for these high-end operating systems. Android is going down the chain of value, covering more and more segments, but it&#8217;s still not in the 50-70 USD price range where Nokia rules. All the others have requirements not even close to that price point.</p>
<p>Nokia has Symbian and a large portion of users that today have a Symbian device and will likely buy another smart phone in the next months. Providing a smooth transition is a key selling point (anyone wants to manually enter all their 1200 contacts in the next phone?).</p>
<p>With both the low-end and the high-end device segments come a lot of developers. It is true that Nokia is not the number one platform to develop today but being the number one vendor for more than 10 years means having contact with thousands of mobile experts. <strong>That is worth something.</strong><br />
Forum Nokia is of course the heart of the Nokia developer community and that means millions of pageviews per month.</p>
<p>Nokia has acquired NAVTEQ and maps have been an integral part of its strategy for the last couple of years. This is actually a GREAT asset as there are basically only two providers of raw cartography, Nokia and TomTom. With those come points of interest (shops, hotels, petrol stations, etc) and years of experience in navigation, of course.</p>
<p>Last but not least there is the Qt development framework. Android and RIM use Java, Microsoft uses .NET and WebOS is, well, Web. Apparently not very interesting, but don&#8217;t forget that Qt developers are normally highly skilled developers breathing Linux and open source software, writing cool hacks and advanced C and C++ in their sleep. That has a GREAT value for anyone that dreams of creating a healthy ecosystem with cool applications that will sell well and will attract customers to their platform.<br />
Along with Qt comes QtWebKit, a port of the great WebKit engine to wrap in native applications. Anyone not taking that into account would be underestimating the power of Web technologies and the desire of Web developers to monetise their content.</p>
<p>Nokia also has a number of services, more or less successful such as Music, Share, contacts and social. I will not go into the details of each, but of course consolidating the users in any existing online service would be great for anyone. Think about Blackberry messenger on 200 million Nokia devices, or Microsoft Live messenger, or finally having someone to talk to on Google Talk. Although none of these is a critical element, they all add to the overall value. A value that Nokia does not want to throw away.</p>
<h1>Conclusions</h1>
<h2>The Microsoft deal</h2>
<p>So the answer to Nokia&#8217;s hunt for a partner is not necessarily who is the best operating system or platform, but rather which one is the best partner. Which one of those companies will get the greatest benefit from Nokia&#8217;s assets and which one will bring the greatest value to Nokia?<br />
Nokia has survived more than 150 years going through multiple mutations, jumping from a market to another, building tires, televisions, PC monitors and boots and eventually mobile phones. While the main focus for the past 15-20 years have been mobile phones, Nokia has diversified its business, it owns NAVTEQ, has a foot in the music distribution business, a foot in advertisement and can provide a great platform to expand pretty much every possible business.</p>
<p>In conclusion Microsoft is the best partner for Nokia because not only it provides many pieces of the puzzle, but it also needs many other pieces.<br />
The partnership with Microsoft will bring great integration in the Maps, IM, advertisement, search, location and more. Both Nokia <strong>AND </strong>Microsoft will give something to the relationship and both will get something out that they did not have before.<br />
It is going to be tough because these are both very large enterprises that have been working on their own for many years and working together will be hard, but they probably both want to make this work.</p>
<h2>The backup plan</h2>
<p>Let&#8217;s not forget that although Nokia is now going to spend a lot of R&amp;D resources to get as many WP7 devices on the market as soon as possible, it will also keep alive MeeGo and Symbian. If the partnership does not work, both parties can walk away and still might retain what has worked well.<br />
This is what today looks like the most likely scenario for a win-win for both companies (yes, I am being cautious).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2011/02/why-microsoft-and-windows-phone-7-is-the-best-way-to-pee-in-your-pants.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sorting User-Agent strings out</title>
		<link>http://blog.trasatti.it/2010/10/sorting-user-agent-strings-out.html</link>
		<comments>http://blog.trasatti.it/2010/10/sorting-user-agent-strings-out.html#comments</comments>
		<pubDate>Fri, 22 Oct 2010 12:23:22 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[device detection]]></category>
		<category><![CDATA[DeviceAtlas]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[user-agent]]></category>
		<category><![CDATA[WURFL]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=570</guid>
		<description><![CDATA[It is very common that over the years something gets more and more cluttered, until at some point someone comes in and decides it&#8217;s time to clean up and start fresh, based on current and up-to-date needs. User-Agent strings, part of the HTTP request headers, are no different and between desktop and mobile browsers, the [...]]]></description>
				<content:encoded><![CDATA[<p>It is very common that over the years something gets more and more cluttered, until at some point someone comes in and decides it&#8217;s time to clean up and start fresh, based on current and up-to-date needs. User-Agent strings, part of the HTTP request headers, are no different and between desktop and mobile browsers, the history is long and the amount of text (some might say useless text) has just kept growing. I am going to try and write down what is important today and why.<br />
<span id="more-570"></span>A little introduction is probably needed. I have been the maintainer of <a href="http://wurfl.sourceforge.net">WURFL</a>, a device database, for about 5 years and then worked on another device database called <a href="http://deviceatlas.com">DeviceAtlas</a> for another 3 years. During these years I also worked with the W3C and in general with the mobile Web community to define how the mobile Web should look like and what developers needed to do their job better.</p>
<p>I am going to take four User-Agent strings for four platforms that are meaningful for mobile and analyse what is useful today, what they have currently and what they <strong>should</strong> have. I will also briefly jump into some other headers as they can help in a number of situations.</p>
<h2>User-Agent string definition</h2>
<p>A clarification here is probably needed. Let&#8217;s start from what the User-Agent string is, if you don&#8217;t know. When an HTTP client such as a Web browser makes a request to a server it sends a number of headers as part of that request. One of these headers is called User-Agent and it is meant to identify the client. This is how it is defined in the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43">RFC-2616</a>:</p>
<blockquote><p>The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests. The field can contain multiple product tokens (section 3.8) and comments identifying the agent and any subproducts which form a significant part of the user agent. By convention, the product tokensare listed in order of their significance for identifying the application.</p></blockquote>
<h3>User-Agent strings in mobile</h3>
<p>In the mobile space specifically this string has historically been used to recognise devices. Since each device has very specific features and installing third party plug-ins has always been (and still is) nearly impossible, recognising a device easily is fundamental to the creation and provision of content that is not only optimised for a device, but often that it is simply supported. In the early 2000 the User-Agent string of a Nokia 7110 was  &#8220;<em>Nokia7110/1.0 (04.84)</em>&#8220;. At that time it gave all the information that was needed. Over the years a lot of information has been added and eventually, recently, a lot of mobile browsers have started emulating the strings that were usually provided by desktop browsers, unfortunately picking up a lot of useless information and removing what was useful.</p>
<h2>The analysis</h2>
<p>Here are my four sample User-Agent strings, an iOS 4.1, an HTC/Google Nexus One, a Nokia N8 and the latest Fennec on an Android device:</p>
<ul>
<li>Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-gb) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7</li>
<li>Mozilla/5.0 (Linux; U; Android 2.2; en-gb; Nexus One Build/FRF83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1</li>
<li>Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaN8-00/010.016; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 BrowserNG/7.2.5.2 3gpp-gba</li>
<li>Mozilla/5.0 (Android; Linux armv7l; rv:2.0b7pre) Gecko/20101006 Firefox/4.0b7pre Fennec/4.0b1</li>
</ul>
<h3>iPhone User-Agent string</h3>
<p>Let me start with the first one, the iPhone. There are a number of things here of interest: that it&#8217;s an iPhone, the software version, the type of browser and possibly the browser version. I will get back to why the browser version may or may not be useful later. Do we care it&#8217;s &#8220;<em>like Mac OS X</em>&#8220;? Do we care that &#8220;<em>KHTML (is), like Gecko</em>&#8220;?<br />
So what we could do is strip out everything that we don&#8217;t need and</p>
<pre>Mozilla/5.0 (<strong>iPhone</strong>; U; CPU iPhone OS <strong>4_1</strong> like Mac OS X; en-gb) \
 <strong>AppleWebKit/532.9</strong> (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 \
 Safari/6531.22.7</pre>
<p>becomes</p>
<pre>iPhone/4.1 AppleWebKit/532.9</pre>
<p>If I was a VP at Apple and had any decision power I would also specify the iPhone model and it&#8217;s probably a good idea to also be explicit about the vendor (it happened that two vendors named two devices the same way). Here is a very short string that tells me everything I need:</p>
<pre>AppleiPhone4/4.1 AppleWebKit/532.9</pre>
<h3>Google Nexus One User-Agent string</h3>
<p>Second on my list is the Nexus One, again a lot of information we don&#8217;t need. Who needs to know it&#8217;s Linux when we can&#8217;t really hack the kernel or install X.org (at least from the browser!)? Who cares about the language when there is an appropriate header for that called <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4">Accept-Language</a>? So what we have is</p>
<pre>Mozilla/5.0 (Linux; U; Android 2.2; en-gb; Nexus One Build/FRF83) \
AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1</pre>
<p>but what we should have is</p>
<pre>GoogleNexusOne/2.2 AppleWebKit/533.1</pre>
<h3>Nokia N8</h3>
<p>Nokia, with the N8 and a lot of other devices has taken the best of all worlds. On one side emulating a desktop browser and on the other side bringing all the extra information about J2ME, audio and video streaming and other details that have been meaningful in the mobile space at some point in time. The sad truth is that all these supported environments and protocols are so fragmented that the name alone is not useful and hence, just a burden. Let&#8217;s clean up the house, remove the information that the device supports MIDP-2.1, because anyone who has ever seen the build-chain of a J2ME application knows that you need to know a lot more about the specific JSRs that are available and of course the device-specific quirks. Also, don&#8217;t forget that this is just an example, Sony Ericsson, Samsung, LG and the other vendors are all more or less the same. So bring some fresh air, leave space for what is important and change this</p>
<pre>Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaN8-00/010.016; \
Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, \
like Gecko) Version/3.0 BrowserNG/7.2.5.2 3gpp-gba</pre>
<p>to this</p>
<pre>NokiaN8/010.016 BNG/7.2.5.2</pre>
<p>In this case specifically, we probably need one little extra information. All the Symbian devices by Nokia in the last few years also have an environment called Web Runtime or WRT that lets you create Web applications that look like native applications, are installed on the device and can access device APIs. So we could use &#8220;B&#8221; or &#8220;BNG&#8221; for the browser and &#8220;W&#8221; or &#8220;WRT&#8221; for the Web Runtime, so if you developed a Web application and  request a remote page, the server will know if it can send extra Javascript to pull up the device location or contacts and so on. It&#8217;s a nice piece of information to know, right?</p>
<h3>Fennec on Android</h3>
<p>Now on with my last example and I am picking Fennec on Android simply because it&#8217;s probably the newest kid on the block, but the exact same comment would be valid for Opera browser and other third party browsers that you can install on your mobile device. For starter, there is no reference to the device, there are a already more than 100 of Android devices, how will I know which one? How will I know if it&#8217;s Android 2.2 with Flash or not? So this is what we have today</p>
<pre>Mozilla/5.0 (Android; Linux armv7l; rv:2.0b7pre) Gecko/20101006 \
Firefox/4.0b7pre Fennec/4.0b1</pre>
<p>This is what we should have (and for the sake of this example I am assuming the device is a Nexus One):</p>
<pre>HTCNexusOne/2.2 Fennec/4.0b1</pre>
<p>Now, you might comment that I will know if Flash is available looking at some other headers. Well this would be true, if the browser sent the appropriate information. If you have been into mobile detection for a little while you will know that since day one you could not trust the Accept header, mostly because browser vendors have been very bullish about their ability to support content, to then generally disappoint their users (and most of all the _customers_ of mobile sites and content providers). For example the Accept header of this Fennec for Android is &#8220;<em>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</em>&#8221; (see the <a href="http://logme.mobi/query/index.php?user_agent=fennec&amp;last10=0&amp;full_headers=on">full headers</a> recorded on logme.mobi). As you can see, this browser supports ANYTHING (the little */* towards the end), isn&#8217;t that great? Now, will it play a real-video? Probably not. Will it play Flash? MAYBE! Will it play an H.264 video? I don&#8217;t know. Oh, yes, these are the same Accept headers that Firefox for PC sends, but it is also true that on my PC or Mac I can download the file and play it with VLC or I might want to download a Word document and read it later. On mobile devices it&#8217;s slightly different and most mobile devices do not let you download and store files and even after I have downloaded it, my context is normally such that if I cannot read the file now I don&#8217;t care. Hence the server needs more information in order to provide the right content; the server might have the file in the right format, if it knew what is supported.</p>
<p>PS: In fairness Opera Mini adds extra headers to tell you the device it is running on, when they know it and this depends on how you installed the client.</p>
<h2>Conclusions</h2>
<p>I am not advocating overloading the headers, we have examples of other headers sent to the servers that are nearly completely useless. Looking at the N8 again, it sends a header about the Music shop version (<em>X-Nokia-Musicshop-Version: 13.1012.15</em>), do I care? Unlikely. Would I care to know the version of Ovi Maps installed so that I can provide a link that will launch the Maps application? More likely!</p>
<p>As you might have noticed, I have stripped the &#8220;<em>Mozilla/</em>&#8221; at the start. There is a myth that servers will not provide the Web site or will provide a very limited version of the site if that string is not there. I have asked many times and although everyone seems scared of this, I do not know of a single site that really does it today. If you know one, please let me know and most of all <strong>WHY </strong>is this site doing this?</p>
<p>One final note, earlier I said that the browser version might not be required. As a rule of thumb I would say that if the server knows the browser version it&#8217;s better because the server will either not care, or if the site actually has different versions for different browsers it can provide that version. In the future I hope that what will matter is just the browser, i.e. is this a standards-compliant browser? If so, I can use Javascript to detect what works and what doesn&#8217;t or I can create my CSS in a way that degrades gracefully. Today, I think we are on the right track and things are quickly moving in the right direction, but we are not there yet, so for the next 1 or 2 years and until everyone gets a new shiny devices with a cool browser, we will have to be a little patient on this and try working together on what is still not solid enough.</p>
<p>So please, if you are browser vendor, take out what is not useful and keep what developers need.﻿</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2010/10/sorting-user-agent-strings-out.html/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Techcrunch and WPTouch: design optimised for mobile, data usage optimised for long wait</title>
		<link>http://blog.trasatti.it/2010/10/techcrunch-and-wptouch-design-optimised-for-mobile-data-usage-optimised-for-long-wait.html</link>
		<comments>http://blog.trasatti.it/2010/10/techcrunch-and-wptouch-design-optimised-for-mobile-data-usage-optimised-for-long-wait.html#comments</comments>
		<pubDate>Tue, 12 Oct 2010 15:54:06 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[WordPress Mobile]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=562</guid>
		<description><![CDATA[Techcrunch, the very well known news site about startups, Web 2.0, mobile and buzz words, has launched a mobile version of their site in March 2010: You Asked For It: TechCrunch, The Mobile Version. There are some little technical details that aren&#8217;t quite perfect for mobiles, though. You might or might not know that the service is [...]]]></description>
				<content:encoded><![CDATA[<p>Techcrunch, the very well known news site about startups, Web 2.0, mobile and buzz words, has launched a mobile version of their site in March 2010: <a title="You Asked For It: TechCrunch, The Mobile Version" rel="bookmark" href="http://techcrunch.com/2010/03/17/techcrunch-mobile/">You Asked For It: TechCrunch, The Mobile Version</a>. There are some little technical details that aren&#8217;t quite perfect for mobiles, though.</p>
<p><span id="more-562"></span></p>
<p>You might or might not know that the service is hosted by wordpress.com and they use <a href="http://wordpress.org/extend/plugins/wptouch/">WPTouch</a> as a mobile theme. WPTouch is normally known as the best WordPress plugin if you want to give an iPhone-like look to your mobile site and we all know how cool is the iPhone nowadays.</p>
<p>This is all good, too bad that while the site looks very good, it is not exactly optimised for performance. I was pleased to notice that WordPress serves the WPTouch theme to Symbian devices like the Nokia N8, less pleased to see the KB downloaded goes up to the stars. The iPhone does not show the data usage in real time, so most of us, including myself, have never noticed this. When I tested this morning the size of the homepage alone was about 1.5MB, yes, 1.5 megabytes!<br />
I tested again this evening on my Mac, emulating the iPhone user-agent and this is what I got</p>
<p><a href="http://blog.trasatti.it/wp-content/uploads/2010/10/TechCrunchWPTouch_resources.png"><img class="alignnone size-medium wp-image-563" title="TechCrunch WPTouch resources" src="http://blog.trasatti.it/wp-content/uploads/2010/10/TechCrunchWPTouch_resources-300x135.png" alt="" width="300" height="135" /></a></p>
<p>As you can see there is a single image using 544KB and then a bunch of other images eating up a lot of memory and bandwidth. The most annoying part is that that image is not even visible! It is hidden in one of the posts and if you don&#8217;t click that post&#8230; Well, you will never see that big, fat image. If you look at the other files, the HTML is just 60KB and all you need is probably in the range of 200KB (CSS, JS, and some basic images). In short, we are wasting 1.3MB &#8211; every time we visit the homepage.</p>
<p>Since this theme is served only to high-end devices why not use a little javascript to load the images when needed? Of course, the way it is now is snappier to open each item on the homepage, but wow, I have to pay for those 1.5MB. Most iPhone users have a nice data flat rate, but a) not all have an iPhone with a contract, b) I still have to wait even if it&#8217;s free and c) this is why operators are getting tired of giving us flat rates.</p>
<p>If you are curious, this is how the TechCrunch homepage looked when I tested, the OneRiot image is a little over 10KB.</p>
<p><a href="http://blog.trasatti.it/wp-content/uploads/2010/10/TechCrunchWPTouch_home.png"><img class="alignnone size-medium wp-image-564" title="TechCrunch WPTouch homepage" src="http://blog.trasatti.it/wp-content/uploads/2010/10/TechCrunchWPTouch_home-300x286.png" alt="" width="300" height="286" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2010/10/techcrunch-and-wptouch-design-optimised-for-mobile-data-usage-optimised-for-long-wait.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WML, Widgets and HTML5 web apps, they are all the same thing</title>
		<link>http://blog.trasatti.it/2010/10/wml-widgets-and-html5-web-apps-they-are-all-the-same-thing.html</link>
		<comments>http://blog.trasatti.it/2010/10/wml-widgets-and-html5-web-apps-they-are-all-the-same-thing.html#comments</comments>
		<pubDate>Mon, 04 Oct 2010 16:32:55 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[W3C]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=546</guid>
		<description><![CDATA[I like to observe how in technology (and often in life) things are repeated. Sometimes they are just the same thing again and again, other times they are slightly different. Especially in technology, some ideas fail because they are missing some pieces or because their timing was not perfect, this of course allows for refinement [...]]]></description>
				<content:encoded><![CDATA[<p>I like to observe how in technology (and often in life) things are repeated. Sometimes they are just the same thing again and again, other times they are slightly different. Especially in technology, some ideas fail because they are missing some pieces or because their timing was not perfect, this of course allows for refinement and repetition.<br />
<span id="more-546"></span></p>
<h2>Glossary</h2>
<p>Some of the terms in this blog post&#8217;s title are buzzwords these days, so let me first clarify what I mean here.</p>
<p><strong>WML</strong>: YES, I really mean the <a title="In short what is WML?" href="http://www.thewirelessfaq.com/in_short_what_is_wml">WML</a> that was part of WAP 1.<br />
<strong>Widgets</strong>: by &#8220;widgets&#8221; I mean the self-contained mini-applications that you can download and install on your mobile device, created with Web technologies like HTML and Javascript. The most obvious examples are of course <a href="http://www.forum.nokia.com/Develop/Web/">Nokia&#8217;s WRT</a> and the <a href="http://www.w3.org/TR/widgets/">W3C&#8217;s Widget Rec</a>, now already implemented in various browsers and devices.<br />
<strong>HTML5 Web app</strong>: Web applications developed as a single-HTML-page that is updated mostly using Javascript, i.e. with almost no page reloads.</p>
<h2>Why WML, Widgets and HTML Web apps are the same thing</h2>
<p>Forget for a moment the technical details or the SDK that you use to create one of these applications. Let&#8217;s start from this sentence:</p>
<blockquote><p>My service is developed using the latest Web technologies, it contains mark-up and scripts, you can download it with a single request and while you use it you will see different content without actually making new requests to the network</p></blockquote>
<p>It might sound crazy, but the above sentence applies to WML, Widgets and HTML web apps. Why? Let me explain.<br />
<strong> WML</strong> is a highly underestimated mark-up that died a cruel and early death because the rest of the technology was not good enough yet (and <em>possibly</em> because it was a bit too strict). On the other hand it had some interesting ideas that have been disregarded for years or we have forgotten too soon. A WML page was called &#8220;a deck&#8221;, a deck was one file with a header and then one or more &#8220;cards&#8221;. Each card was rendered as a page on your mobile device and you could use anchors to jump from a page to another. The main reason for this was to save network requests, i.e. download everything you need in one go and then browse within that content until you need more.<br />
A<strong> Widget</strong>, in the context I described above, is normally one HTML page, some CSS, some Javacript and an XML file that acts as a descriptor. You download and install it on your mobile device. When you run it, a sandboxed browser opens your starting HTML page and some Javascript and CSS magic loads the content and updates it according to your actions. Of course it is much more advanced than what WML (and WMLScript) did, but 10 years have also gone! What are the key selling points of a widget? That once installed on your mobile device it looks like a native application and that you have the markup pre-loaded in your device&#8217;s memory. IMHO, it sounds a lot like a pre-loaded WML page and in fact something that was also possible with WAPPush (you would send a compiled WML page via SMS and the device would parse it and display it).<br />
An <strong>HTML5 Web app</strong> is not rocket science and in fact Web apps existed way before HTML5. Think about Gmail, it&#8217;s a Web page, but you never hit the &#8220;back&#8221; button or load a new page. In essence Gmail (like any single-page Web app) is one Web page with a lot of CSS and Javascript that load and update different parts of the page. VERY similar to a widget with regards to both technology and functionality, much more advanced than a deck in WML, but not so different in concept.</p>
<h2>So what&#8217;s the story?</h2>
<p>The two ideas might have started from different assumptions, for WML it was a matter of saving network requests, for Widgets was the idea of creating an application that looked native, but was as simple as a Web page and for HTML5 it was a bit of both, look like a native application and optimise network requests. The end result seems to be the same.</p>
<p>Of course, the road to success (if we can already declare Web apps a success) has been paved with many tiles that were missing at the time of WML and even when the first Widget implementations came. We now have much better connectivity and lower latency, we have better Javascript engines and a way of styling pages that allows to manipulate elements in the page easily.</p>
<p>If you are like me and thought that Widgets were not interesting, what is your thinking with HTML5? Why is an HTML5 Web app any better than a widget?<br />
A Web app is downloaded from a URI and is always up-to-date, but updating a Widget is almost as easy. A widget can be installed in your device and appear as an icon like a native application, but you can also save a bookmark of a Web app and some devices let you add shortcuts to bookmarks in your mobile device&#8217;s menus.</p>
<p>So can we call Widgets useless and love Web apps? Can we call WML a complete failure?<br />
Are these just names created by marketing and sales teams for the same thing?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2010/10/wml-widgets-and-html5-web-apps-they-are-all-the-same-thing.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Analytics for WordPress for Mobile update</title>
		<link>http://blog.trasatti.it/2010/08/google-analytics-for-wordpress-for-mobile-update.html</link>
		<comments>http://blog.trasatti.it/2010/08/google-analytics-for-wordpress-for-mobile-update.html#comments</comments>
		<pubDate>Tue, 24 Aug 2010 20:51:37 +0000</pubDate>
		<dc:creator>Andrea</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Mobile Web]]></category>
		<category><![CDATA[WordPress Mobile]]></category>

		<guid isPermaLink="false">http://blog.trasatti.it/?p=534</guid>
		<description><![CDATA[I thought about a possible issue where a low-end mobile device would have gotten the img tag in the head tag. Not good. While I was editing the code I also improved the code segmentation part that in some cases might have sent incomplete data. I have written an update, should be much better. Still [...]]]></description>
				<content:encoded><![CDATA[<p>I thought about a possible issue where a low-end mobile device would have gotten the img tag in the head tag. Not good.</p>
<p>While I was editing the code I also improved the code segmentation part that in some cases might have sent incomplete data.</p>
<p>I have written an update, should be much better.<span id="more-534"></span></p>
<p>Still to do is the AdSense integration and managing the manual placing of the javascript/img.</p>
<p>If you were testing the previous version of the script, please <a href="http://blog.trasatti.it/wp-content/uploads/2010/08/google-analytics-for-wordpress-mobile.4.0.8-1.zip">upgrade</a> now!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trasatti.it/2010/08/google-analytics-for-wordpress-for-mobile-update.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
