<?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>techno.blog(&#34;Dion&#34;) &#187; JavaScript</title>
	<atom:link href="http://almaer.com/blog/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Fri, 30 Jul 2010 00:42:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Capability based JavaScript loading; JS libraries catch up to GWT</title>
		<link>http://almaer.com/blog/capability-based-javascript-loading-js-libraries-catch-up-to-gwt</link>
		<comments>http://almaer.com/blog/capability-based-javascript-loading-js-libraries-catch-up-to-gwt#comments</comments>
		<pubDate>Thu, 29 Jul 2010 16:07:33 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2723</guid>
		<description><![CDATA[
Web developers have to walk around dragging a ball and chain. It is fantastic that we have a ridiculous install base (browsers, the Web runtimes) and a dynamic language in JavaScript.
The ball and chain though is the fact that we have to care so much about the payload of the application that we write. Less [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/justinshearer/172164624/"><img src="http://almaer.com/blog/uploads/ballandchain.jpg" alt="ballandchain" title="ballandchain" width="500" height="333" class="alignnone size-full wp-image-2724" /></a></p>
<p>Web developers have to walk around dragging a ball and chain. It is fantastic that we have a ridiculous install base (browsers, the Web runtimes) and a dynamic language in JavaScript.</p>
<p>The ball and chain though is the fact that we have to care so much about the payload of the application that we write. Less code means less bytes to download, and less for the JS runtime to load up.</p>
<p>This has bad consequences:</p>
<ul>
<li>You are tempted to write hard to understand code
<li>You have to balance functionality and code size much more than other environments
<li>You end up getting tricky and come up with ways to dynamically load modules on demand
<li>All of this time is time not spent on the app logic.
</ul>
<p>When you run into a problem like this in computer science what do you do? Build an abstraction!</p>
<p>GWT has done a great job here. It&#8217;s very nature requires a compilation step, and once you have to deal with that step&#8230;. you can do a lot at build time to change the above dynamics.</p>
<p>For example:</p>
<ul>
<li>You can write nice explicit source code, and trust that the compiler will output optimized JS (which can look as ugly as sin for all anyone cares)
<li>Your application can get faster with a new release of GWT, as the compiler gets better
<li>A lot of <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideOptimizing.html">advanced techniques</a> such as code splitting, and deferred binding can be applied to allow logic to apply at build time as well as runtime.
</ul>
<p>Ignoring GWT, when you write a pure JS application for the Web, you are writing a cross platform application. Unlike clean portable C, you don&#8217;t have that compilation step to do clean up work for you on each platform, so you end up with a lot of runtime conditional logic.</p>
<p>You try to do object detection rather than user agent conditional, but still, you end up both downloading the code necessary to run in all environments, and you have the overhead of loading and executing that code.</p>
<p>Chances are you are smart and don&#8217;t do <code>if()</code> checks all the time, but maybe do so once when loading up. For large chunks of big differences, maybe you do something like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Foo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>sometest<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do it like this</span>
<span style="color: #009900;">&#125;</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do it like that</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you take a look at some parts of popular JavaScript frameworks, you see that they are abstractions or fixes for various browsers. As browsers have stepped up to the plate recently, they have fixed a lot, and suddenly you take a step back. A lot of frameworks have a chunk of code to give us the ability to do smart things with CSS querying. Modern browsers support <code>querySelectorAll</code> (even with some bugs) and <code>getElementsByClassName</code> so a lot of the code is un-needed&#8230;. unless you care about the old browsers.</p>
<p>We shouldn&#8217;t have to download all of that cruft on the other side of the <code>if()</code> statement when we don&#8217;t use it!</p>
<p>The GWT compiler can output versions of your application targeted to a given browser. Only the fastest, minimal code, will get sent down. Deferred binding goes far beyond just browser type (can deal w/ locales and much more) too.</p>
<p>GWT isn&#8217;t the only horse in this race though.</p>
<p>Alex Russell started to sprinkle in some directives to Dojo that would enable you to do a build that is WebKit targeted. A major use case for all of this is making sure that you are sending down lean code in the mobile space. It can matter everywhere, but when you are dealing with grown up walkie talkies&#8230;. you want to really optimize.</p>
<p>And this brings us to YUI. I was really excited to see some of the features in the <a href="http://www.yuiblog.com/blog/2010/07/26/3-2-0pr1/">YUI 3.2.0 preview release</a>. Great stuff for touch/gesture support, but what stood out for me was &#8220;YUI’s intrinsic Loader now supports capability-based loading&#8221;. A-ha!</p>
<p>I poked around <a href="http://github.com/yui/yui3/">the source</a> to see how it was used. Here is one fake example that shows how it works. When you boot up YUI you can add in &#8220;conditions&#8221; which are in charge of working out whether to load something. You can currently tie on to user agent, or write a test function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YUI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    modules<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        lib2<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            requires<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'yui'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            fullpath<span style="color: #339933;">:</span> <span style="color: #3366CC;">'js/lib2.js'</span><span style="color: #339933;">,</span>
            condition<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                trigger<span style="color: #339933;">:</span> <span style="color: #3366CC;">'node-base'</span><span style="color: #339933;">,</span>
                ua<span style="color: #339933;">:</span> <span style="color: #3366CC;">'gecko'</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
        lib3<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            requires<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'yui'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            fullpath<span style="color: #339933;">:</span> <span style="color: #3366CC;">'js/lib3.js'</span><span style="color: #339933;">,</span>
            condition<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                trigger<span style="color: #339933;">:</span> <span style="color: #3366CC;">'event-base'</span><span style="color: #339933;">,</span>
                test<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>Y<span style="color: #339933;">,</span> req<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> Y.<span style="color: #660066;">UA</span>.<span style="color: #660066;">gecko</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>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #003366; font-weight: bold;">use</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'node'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>Y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> .... <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The YUI team uses this themselves to only load certain ugly DOM stuff for IE6 when needed:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;dom-style-ie&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;condition&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;trigger&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;dom-style&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #3366CC;">&quot;ua&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ie&quot;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
    <span style="color: #3366CC;">&quot;requires&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #3366CC;">&quot;dom-style&quot;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
YUI.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'dom-style-ie'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>Y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// ....</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This makes a ton of sense, especially for the libraries themselves to do this work. They are the ones that do the heavy lifting of cross browser ugliness, all to allow us to write to an API that works. </p>
<p>Beyond that, we can then ourselves split out code if it becomes a performance issue.</p>
<p>Of course, the value of the <code>test()</code> function is that you can do capability based testing (not just user agent testing&#8230;. hence the name!). This means that you can do a test say for Canvas support (as Zach mentions in the comments) <code>document.createElement(’canvas’).getContext</code>, and load up excanvas or another shim library if it doesn&#8217;t exist.</p>
<p>Using modernizr and ilk, we could build out &#8220;plugins&#8221; for YUI that auto load based on common capabilities. You can imagine running a YUI build, having it detect that you are using a capability, and then automatically load up a plugin that has the condition all loaded up. What a great user experience as a developer!</p>
<p>Maybe it makes sense to come up with a common pattern and conventions for dealing with this issue. How do you name your CSS/JS? Do we setup server side hooks so we don&#8217;t even need loaders necessarily?</p>
<p>I can certainly see a day where you may be asking the Google Ajax Library service for jquery.js, but it is returning jquery.ie.js to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/capability-based-javascript-loading-js-libraries-catch-up-to-gwt/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Diffable; What if GitHub supported it natively?</title>
		<link>http://almaer.com/blog/diffable-what-if-github-supported-it-natively</link>
		<comments>http://almaer.com/blog/diffable-what-if-github-supported-it-natively#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:24:42 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2718</guid>
		<description><![CDATA[Steve Souders told me about Diffable, when I saw him after his awesome Velocity conference.
Diffable is an open source project that allows you to only send down the deltas in your application versions, versus full new downloads (which may have a large amount of duplicate data).
In their presentation, Josh Harrison and James deBoer, talk about [...]]]></description>
			<content:encoded><![CDATA[<p>Steve Souders told me about <a href="http://www.stevesouders.com/blog/2010/07/09/diffable-only-download-the-deltas/">Diffable</a>, when I saw him after his awesome Velocity conference.</p>
<p>Diffable is <a href="http://code.google.com/p/diffable/">an open source project</a> that allows you to only send down the deltas in your application versions, versus full new downloads (which may have a large amount of duplicate data).</p>
<p>In their <a href="http://docs.google.com/present/view?id=dhp4jpqq_58hmf8zxdk">presentation</a>, Josh Harrison and James deBoer, talk about the details after the start with the core issues:</p>
<blockquote><p>
<b>Problem:</b></p>
<p>Frequently modified web resources must be downloaded in their entirety with every modification.<br />
Even a small change invalidates the cache.<br />
Rich internet applications often have large amounts of static content.</p>
<p><b>Idea:</b></p>
<p>Initial application resources kept in cache.<br />
Changes to cached versions transmitted as deltas.<br />
Deltas merged client-side to generate latest JS version.</p>
<p><b>Benefits:</b></p>
<p>Faster page load times for users with cached resources.<br />
Small changes to large resources incur only small costs.
</p></blockquote>
<p>Steve summarizes things well in his post:</p>
<blockquote><p>
Diffable uses differential compression to reduce the size of JavaScript downloads. It makes a lot of sense. Suppose your web site has a large external script. When a new release comes out, it’s often the case that a bulk of that large script is unchanged. And yet, users have to download the entire new script even if the old script is still cached.</p>
<p>Josh and James work on Google Maps which has a main script that is ~300K. A typical revision for this 300K script produces patches that are less than 20K. It’s wasteful to download that other 280K if the user has the old revision in their cache. That’s the inspiration for Diffable.</p>
<p>Diffable is implemented on the server and the client. The server component records revision deltas so it can return a patch to bring older versions up to date. The client component (written in JavaScript) detects if an older version is cached and if necessary requests the patch to the current version. The client component knows how to merge the patch with the cached version and evals the result.</p>
</blockquote>
<p>With this technique in action, you end up sending down JS arrays as deltas that looks like:</p>
<pre>
[0,10,"red",40,3," leaps",25,15,16,3,"."]
</pre>
<p>The data that these guys share is impressive. The results seem to add up for applications as large as Google Maps. Do they measure up for smaller apps? If large apps have a lot of static content, couldn&#8217;t that content be put into another download and even app cached away?</p>
<p>Also, it is a lot of work to implement this for a developer. Work on both client side and server side. It would be great if we can experiment with Diffable and then move things lower into the stack. Why can&#8217;t HTTP itself be smart enough to deal with diffs?</p>
<p>It did make me think of my favourite chaps @github. I know that GitHub is about development rather than deployment&#8230;. but what if they supported this natively (since they kinda grok diffin&#8217; etc already) and offered a client side loader so you could <code>github.load("project", ...)</code>.</p>
<p>It all just makes me realise that GitHub is poised to pounce in many directions. Good on &#8216;em.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/diffable-what-if-github-supported-it-natively/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building an Web application from the inside out; Using node.js to bootstrap a server from client JS</title>
		<link>http://almaer.com/blog/building-an-web-application-from-the-inside-out-using-node-js-to-bootstrap-a-server-from-client-js</link>
		<comments>http://almaer.com/blog/building-an-web-application-from-the-inside-out-using-node-js-to-bootstrap-a-server-from-client-js#comments</comments>
		<pubDate>Mon, 15 Feb 2010 16:20:58 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[webOS]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2625</guid>
		<description><![CDATA[
Over the winter holiday, Ben and I whipped together Project Appetite, an open source example that consumes the feeds from the Palm application ecosystem (both Palm Catalog and Web distribution). We didn&#8217;t have long to come up with something, and one of the interesting stories was how we took an API and mocked up the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://almaer.com/blog/uploads/palmappetite-1024x752.png" width="480"></p>
<p><a href="http://almaer.com/blog/palm-developer-program-opens-at-ces-a-big-appetite-with-a-plug-in-development-kit-1m-dollars-of-rewards-and-more">Over the winter holiday</a>, Ben and I whipped together <a href="http://projectappetite.com/">Project Appetite</a>, an open source example that consumes the feeds from the Palm application ecosystem (both Palm Catalog and Web distribution). We didn&#8217;t have long to come up with something, and one of the interesting stories was how we took an API and mocked up the middle, allowing server and client to get going quickly.</p>
<p>The feeds that the Palm ecosystem puts out are RSS 2.0 XML feeds, with extra catalog-y info in an &#8220;ac&#8221; namespace. We converted the format to JSON to make life easier for the JavaScript client consumer. Although you can <code>DOMParser()</code> away (and use the Microsoft component) JSON is just so much easier. What lives at <a href="http://api.projectappetite.com/">api.projectappetite.com</a> is the result of the munging, so others could consume JSON directly if they so wish.</p>
<p><b>The Data</b></p>
<p>We quickly put together some dummy data, and for ease, put it in a file <code>app.js</code> that the client could consume. Once we iterated on the format, one of us could go off and write the XML to JSON code. We actually implemented this in a variety of ways as we experimented. Ben created a simple JDOM translation, and I fought with databinding, which still seems to be a royal pain with Java. The reason I checked that out was to create an open backend on app engine, and I wanted to go from XML to JSON to Java for persistence via JDO. From one set of Java objects I could <code>@PersistenceCapable</code> and <code>@XStreamAlias("asset_url")</code>. It wasn&#8217;t worth the effort.</p>
<p><b>The Client</b></p>
<p>We created an <code>Appetite</code> object that would be able to query the model and get the data that was needed. The constructor took the apps data, and then it did its magic. In this case is created some caches to make querying fast.</p>
<p>The public API contained:</p>
<ul>
<li>app(id, locale): returns a single app based on id</li>
<li>find(opts): the core engine for querying the app data</li>
<li>types: contained the logic for filtering on top rated, top paid, newest, etc</li>
<li>sorts: contained the sorting functions to return the data in the right order (e.g. by download count versus date)</li>
</ul>
<p>Very quickly the client was mocked up and the frontend was build out using this API. Again, at this point the entire front end could be built without waiting for server infrastructure.</p>
<p><b>The Server</b></p>
<p>Since the client API mocked out the functionality needed for the frontend, the server could actually reuse this logic. This is when the <a href="http://nodejs.org/">node.js</a> server was born.</p>
<p>To play nice with node, we went back to the other files and added logic to export the data. E.g. in the client.js:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// check to see if you are running inside of node.js and export if you are</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> GLOBAL <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;object&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">typeof</span> GLOBAL<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'node'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    exports.<span style="color: #660066;">Appetite</span> <span style="color: #339933;">=</span> Appetite<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Once that was in place, we could load up all of the information that we need:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// -- Load up the libraries</span>
<span style="color: #003366; font-weight: bold;">var</span> sys   <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sys&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   http   <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   posix  <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posix&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   apps   <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./apps&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">apps</span><span style="color: #339933;">,</span>
   client <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./client&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And then we can get access to the client API via:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> client.<span style="color: #660066;">Appetite</span><span style="color: #009900;">&#40;</span>apps<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We created a simple mapping that enabled a URL such as <code>/app?id=[id]&#038;locale=*</code> to be converted to a method call of <code>app({id:id, locale:locale})</code>. We did this in a generic way that enabled us to add URL endpoints by simply added to the responder hash. The functions would return an object that could contain error codes and the like.</p>
<p>For example, the app end point:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// /app?id=[id]&amp;locale=*</span>
app<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>params<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>params.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
            error<span style="color: #339933;">:</span> <span style="color: #CC0000;">501</span><span style="color: #339933;">,</span>
            body<span style="color: #339933;">:</span> <span style="color: #3366CC;">'I need an id!'</span> 
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
        body<span style="color: #339933;">:</span> a.<span style="color: #660066;">app</span><span style="color: #009900;">&#40;</span>params.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p>We also added a magical DEFAULT handler to take care of bad URLs.</p>
<p>Finally, we would boot up the listening server and handle responses:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// -- Create the HTTP server binding</span>
<span style="color: #003366; font-weight: bold;">var</span> host <span style="color: #339933;">=</span> process.<span style="color: #660066;">ENV</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'APPETITE_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> port <span style="color: #339933;">=</span> process.<span style="color: #660066;">ENV</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'APPETITE_PORT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #CC0000;">8000</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>process.<span style="color: #660066;">ARGV</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// overwrite with command line args</span>
    port <span style="color: #339933;">=</span> process.<span style="color: #660066;">ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>process.<span style="color: #660066;">ARGV</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    host <span style="color: #339933;">=</span> process.<span style="color: #660066;">ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
http.<span style="color: #660066;">createServer</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> path <span style="color: #339933;">=</span> request.<span style="color: #660066;">uri</span>.<span style="color: #660066;">path</span>.<span style="color: #660066;">substring</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: #003366; font-weight: bold;">var</span> output<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> responder <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> responders<span style="color: #009900;">&#91;</span>path<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;function&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> responders<span style="color: #009900;">&#91;</span>path<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> responders<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'DEFAULT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    output <span style="color: #339933;">=</span> responder<span style="color: #009900;">&#40;</span>request.<span style="color: #660066;">uri</span>.<span style="color: #660066;">params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> contentType <span style="color: #339933;">=</span> output.<span style="color: #660066;">contentType</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>output.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        response.<span style="color: #660066;">sendHeader</span><span style="color: #009900;">&#40;</span>output.<span style="color: #660066;">error</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;Content-Type&quot;</span><span style="color: #339933;">:</span> contentType <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        response.<span style="color: #660066;">sendBody</span><span style="color: #009900;">&#40;</span>output.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</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>
        <span style="color: #003366; font-weight: bold;">var</span> body <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>contentType <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>output.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> output.<span style="color: #660066;">body</span><span style="color: #339933;">;</span>
        response.<span style="color: #660066;">sendHeader</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;Content-Type&quot;</span><span style="color: #339933;">:</span> contentType <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        response.<span style="color: #660066;">sendBody</span><span style="color: #009900;">&#40;</span>body<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    response.<span style="color: #660066;">finish</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span>port<span style="color: #339933;">,</span> host<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After 86 verbose, commented code, we had a server that would respond to URLs and return data. And in this time the frontend continued to be built out.</p>
<p>Being able to reuse the client JS and wrap it to become a server was a lot of fun. I am definitely a big node.js fan! Now, I am looking forward to doing a lot more with Project Appetite&#8230;. but for now we are working on a pretty cool webOS application, and getting the developer platform better and better.</p>
<p><b>Some coffee in your Node</b></p>
<p>In an aside, <a href="http://gist.github.com/304374">the node hello world has been ported to CoffeeScript</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"># To run<span style="color: #339933;">,</span> first install node and coffee<span style="color: #339933;">-</span>script
# Node<span style="color: #339933;">:</span> http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//nodejs.org/#download</span>
# CoffeeScript<span style="color: #339933;">:</span> http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//github.com/jashkenas/coffee-script</span>
#
# <span style="color: #000066; font-weight: bold;">In</span> a terminal window<span style="color: #339933;">:</span>
# $ cd coffee<span style="color: #339933;">-</span>script
# $ .<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>node_coffee <span style="color: #339933;">-</span>r hello_web.<span style="color: #660066;">coffee</span>
# Tested <span style="color: #000066; font-weight: bold;">with</span> Mac OS X 10.5.8<span style="color: #339933;">,</span> Node 0.1.26<span style="color: #339933;">,</span> CoffeeScript 0.5.0
&nbsp;
sys<span style="color: #339933;">:</span> require <span style="color: #3366CC;">&quot;sys&quot;</span>
http<span style="color: #339933;">:</span> require <span style="color: #3366CC;">&quot;http&quot;</span>
&nbsp;
http.<span style="color: #660066;">createServer</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>req<span style="color: #339933;">,</span> res<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span>
  res.<span style="color: #660066;">sendHeader</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;Content-Type&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;text/plain&quot;</span><span style="color: #009900;">&#125;</span>
  res.<span style="color: #660066;">sendBody</span> <span style="color: #3366CC;">&quot;Hello, World!&quot;</span>
  res.<span style="color: #660066;">finish</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">listen</span> <span style="color: #CC0000;">8000</span>
&nbsp;
sys.<span style="color: #660066;">puts</span> <span style="color: #3366CC;">&quot;Server running at http://127.0.0.1:8000/&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/building-an-web-application-from-the-inside-out-using-node-js-to-bootstrap-a-server-from-client-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Developers are not arrogant and stupid :)</title>
		<link>http://almaer.com/blog/iphone-developers-are-not-arrogant-and-stupid</link>
		<comments>http://almaer.com/blog/iphone-developers-are-not-arrogant-and-stupid#comments</comments>
		<pubDate>Mon, 23 Nov 2009 19:18:00 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[webOS]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2571</guid>
		<description><![CDATA[

I love your work and respect you, @ppk, but you just wrote a very naïve post. Guessing @dalmaer slipped you a mickey, so I&#8217;ll forgive you.

I did see PPK with a drink, but I didn&#8217;t drop anything in it, I promise! :)
What are we talking about here? PPK has written a post commenting on the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://almaer.com/blog/uploads/webexp.jpg" alt="webexp" title="webexp" width="500" height="500" class="alignnone size-full wp-image-2573" /></p>
<blockquote><p>
I love your work and respect you, @ppk, but you just wrote a very naïve post. Guessing @dalmaer slipped you a mickey, so I&#8217;ll forgive you.
</p></blockquote>
<p>I did see PPK with a drink, but I didn&#8217;t drop anything in it, I promise! :)</p>
<p>What are we talking about here? <a href="http://www.quirksmode.org/blog/archives/2009/11/apple_is_not_ev.html">PPK has written a post commenting on</a> the interesting &#8220;<a href="http://www.paulgraham.com/apple.html">Apple&#8217;s mistake</a>&#8221; essay by Paul Graham.</p>
<p>I love PPK and he is doing great work, but I have to respectfully point out a few things here, especially as some folks thought I put him up to it. For those who are jumping on him in entirety, here does have some things right too! Don&#8217;t just get mad at the fact that he called developers arrogant and stupid ;)</p>
<p>There are fantastic web applications on the iPhone. I use Gmail and Google Reader as a Web app, for example. The browser is good, but I have written many times (before being a Palm employee! These are my thoughts&#8230; blah blah) about how I wished that Apple let me go the extra mile and access more from the Web side of things.</p>
<p>Although you can do great apps like Gmail, the user experience available to Web developers isn&#8217;t anywhere as close to that of the iPhone SDK.</p>
<ul>
<li>APIs: You are unable to access the rich APIs on the device. Sure you can get local storage and appcache, but you can&#8217;t get to the compass and the [insert tons of APIs here]. Your app may not need it, but they may be able to greatly benefit from them&#8230; let alone the enhanced graphics and performance.</li>
<li>Discoverability: There are two worlds. The Web and the App Store. How does a user find out about your Web app? Sure they could use the power of Google etc&#8230;. but if they are trained not to do that anymore? Fortunately we have PhoneGap and Titanium and &#8230; stepping up here</li>
</ul>
<p>So, the feeling of &#8220;come on iPhone devs, don&#8217;t be stupid and just develop a web app!&#8221; is going a tad too far. There are very valid reasons to use native. With PhoneGap et al, there are growing reasons to cover various bases.</p>
<p>At Palm I am excited to push the Web stack further by having it as <em>the</em> SDK, not as an option in the browser. I believe that the Web can be the unifying platform across the multitudes of devices that users will have in the future. This world is going to cause a large number of changes to how we develop experiences, and I am excited by the challenge and working with the Web community (companies and individuals) to meet the challenge.</p>
<p>There is so much to be done on both the technology side (html5 on devices, apis, services, gpu, etc) and on the delivery side (future of app stores, richer discoverability, etc). You can also create fantastic applications for many platforms using Web technology TODAY!</p>
<p><b>Update</b></p>
<p>Faruk Ateş has written a <a href="http://farukat.es/journal/2009/11/347-iphone-developers-arent-stupid-ppk">detailed post on this topic too</a> that discusses similar issues to my post above, but also goes beyond with more details on $, and the SDK experience.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/iphone-developers-are-not-arrogant-and-stupid/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Getting Closure: Don&#8217;t just use it, don&#8217;t just abuse it</title>
		<link>http://almaer.com/blog/getting-closure-dont-just-use-it-dont-just-abuse-it</link>
		<comments>http://almaer.com/blog/getting-closure-dont-just-use-it-dont-just-abuse-it#comments</comments>
		<pubDate>Mon, 23 Nov 2009 16:01:36 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2564</guid>
		<description><![CDATA[

“Just what the world needs—another sucky JavaScript library,” he said. When I asked him what made it ‘sucky’, he elaborated. “It’s a JavaScript library written by Java developers who clearly don’t get JavaScript.”

This quote is by Kevin Yank, talking to Dmitry Baranovskiy, author of the fantastic Raphaël graphics abstraction library. He writes up more on [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://almaer.com/blog/uploads/closure.jpg" alt="closure" title="closure" width="500" height="333" class="alignnone size-full wp-image-2565" /></p>
<blockquote><p>
“Just what the world needs—another sucky JavaScript library,” he said. When I asked him what made it ‘sucky’, he elaborated. “It’s a JavaScript library written by Java developers who clearly don’t get JavaScript.”
</p></blockquote>
<p>This quote is by Kevin Yank, talking to <a href="http://dmitry.baranovskiy.com/">Dmitry Baranovskiy</a>, author of the fantastic Raphaël graphics abstraction library. He <a href="http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/">writes up more on the issues they see with Closure</a>. This is the few of one side of the community towards the open source release of Google Closure and its tools.</p>
<p>It was bound to happen. When I started at Google I quickly wanted to learn about how Gmail, Google Maps, and all the revolutionary front ends that helped make Ajax happen. Closure was the heart of it, and I quickly wanted to see a way to get the knowledge out there. This was years ago now, but the same reasons permeate through. Even at the time there were a ton of great JavaScript libraries. It wasn&#8217;t that I wanted Google to come down the mountain like Moses and bless the world &#8220;thou shalt use Closure!&#8221; However, some smart people had worked for some time refining their use of the browser runtime and Closure was the art and science of that ongoing experiment. Having the world able to at least see the experiment would be a good thing. Other libraries could learn from it.</p>
<p>No one from Google has said that you should, or must use Closure!</p>
<p>I realize that we live in a world of heros or zeroes. There isn&#8217;t room for much in between. You are either going to be a X killer, or you are killed by X. There is no time to tell the longer arching tale. Closure came to us late in the game, where folks are often perceived to be in their camps. I love JavaScript because it allows a diverse group of libraries to do what they do best. Developers and designers can find what suits both their personalities and their particular project.</p>
<p>If someone asks me (and they often do) &#8220;Which Ajax library should I use?&#8221; there isn&#8217;t a simple answer. It is nuanced. It is complicated. It is frustrating! How many of you have even changed libraries in a project? It is embarrassing to go back in time and see what happened with Bespin. At various times we had MooTools, Prototype, Dojo, and SproutCore. Is that productive? Obviously no.</p>
<p>You build many things on the Web. A web site isn&#8217;t a web application, and then blend together so you often can&#8217;t tell when you go from one to the other (and it doesn&#8217;t of course matter at all). jQuery has made a living starting out as a fantastic DSL for sprinkling behaviour onto web sites and going from there. SproutCore and Cappuccino are the other extreme, and Dojo was the kitchen sink of JS development a long time ago. Speaking of Dojo, I really wish that Dojo and Closure had collided a long time ago. I think that it would have benefitted both sides, even though I know that it would have added some overhead for both too. When you are on an internal framework it is built for your needs. If you take a look at the Closure components they feel very Googley out of the box. At the end of the day though, Dojo and Closure are so similar in many ways, that having them joint at the hip a few years back would have been really exciting. C&#8217;est la vie.</p>
<p>One tricky thing about Closure is that you can&#8217;t look at all of the widgets and packages equally (same for most libraries to be fair). Some are battled hardened to the hilt as they are on important production systems acting as core functionality. The keyboard handling and localization support is top draw. Others may be cool but placed in via an interesting 20% project that isn&#8217;t as mission critical and hence battle hardened. Not all code is equal. In fact, I find the line by line code criticism tiring. It is so easy to take someones code and find fault with it (at least perceived fault). I am sure there is bad code in Closure. That is true for all code. It is much harder to be a creator though. Don&#8217;t get me wrong, it is good to point out potential issues, but there is a big difference between:</p>
<blockquote><p>
&#8220;I noticed that code X does Y. I think there is a bug there that would affect &#8230;.&#8221;
</p></blockquote>
<p>and</p>
<blockquote><p>
&#8220;Code X SUCKS. Mwhahahahahah. SUCKS!&#8221;
</p></blockquote>
<p>My new years resolution for 2010: &#8220;Say *sucks* less&#8221;.</p>
<p>The criticism that made me laugh hardest was the assertion that the Closure engineers were Java folks who wanted JS to be Java. They are far from it. They are old school JS engineers who have done amazing things on the Web and have just learned a few things along the way as they build huge scale JS systems.</p>
<p>Google is of course a big place with engineers with opinions :) When you have the creators of various languages and platforms under one roof that is always going to be the case (From Python to C++ to Java to Go, and then Closure, GWT, etc on the JS side&#8230; even jQuery ;). Many of the frontend engineers aren&#8217;t fans of Closure (as in: doesn&#8217;t fit them) but they do understand where some of the strengths are. Some of the engineers have even weighed in:</p>
<blockquote><p>
<em>NOTE: The following quotes were taken from a Facebook comment stream. There is context missing (for example, Joel talks below about how he didn&#8217;t use the term &#8216;natives&#8217; for example</em></p>
<p><em>Joel Webber, GWT guru</em>: &#8220;I&#8217;m unfortunately not too surprised to see self-appointed &#8220;Javascript natives&#8221; pissing all over Closure, because it tells them something they don&#8217;t want to hear &#8212; namely, that you can&#8217;t get enough optimization leverage on large applications without some constraints on your code&#8217;s structure. The kind of stuff that you see in many Javascript libraries (e.g. lots of dynamic tests to figure out what to do in a function) pretty much guarantees that you&#8217;ll have an unoptimizeable mess.&#8221;</p>
<p><em>Gavin Doughtie, Dojo and Google Photos</em>: &#8220;As one of the Javascript natives, I must say after three years of using Closure that it gives you a nice split between development-time dynamism and deployment-time optimization. I have found few Javscript idioms unavailable to me when coding, yet still benefit from static checking and optimizations once I&#8217;m ready to ship.&#8221;
</p></blockquote>
<p>I am more of a JavaScript native than anything else. I am not going to be rushing to use Closure on a project any time soon. It doesn&#8217;t fit many of the projects I work on to be honest, and it doesn&#8217;t fit me as well as some of the other libraries.</p>
<p>That being said, I am thankful to Google for putting this code in the commons (and the fantastic tools around it!) so we can all check it out (and some of us use it). I hope that the hard part of open sourcing a project kicks in and we see a community form around it, including taking in contributions. I still also harbor the hope that Dojo and Closure joined forces, but that is hard to do (a lot of people using both code bases!)</p>
<p>When it comes to getting closure, I hope that you don&#8217;t jump to the extreme and ignore and abuse it, and I also hope that you also don&#8217;t think that you SHOULD use it without checking it out and understanding the tradeoffs.</p>
<p>For example, this is crazy:</p>
<blockquote><p>
&#8220;I hate to admit but I “might” have switched from jQuery to Closure strictly because of the Google brand.&#8221;
</p></blockquote>
<p><b>Roundup on Closure</b></p>
<ul>
<li><a href="http://erik.eae.net/archives/2009/11/05/22.27.29/">Erik Arvidsson, founder of Closure, awesome JS hackers, on the history</a>
<li><a href="http://alex.dojotoolkit.org/2009/11/a-bit-of-closure/">Alex Russell, founder of Dojo and Chrome Frame</a>
<li><a href="http://www.slideshare.net/Dmitry.Baranovskiy/your-javascript-library">Dimitry presentation on JavaScript libraries</a>
<li><a href="http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/">Google Closure: how not to write JavaScript</a>
<li><a href="http://caprazzi.net/posts/learning-closure-ajax-with-goog-net/">Learning Closure with goog.net</a>
<li><a href="http://bolinfest.com/javascript/inheritance.php">Inheritance Patterns in JavaScript</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/getting-closure-dont-just-use-it-dont-just-abuse-it/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cleanup of manual animation via Dojo Animation</title>
		<link>http://almaer.com/blog/cleanup-of-manual-animation-via-dojo-animation</link>
		<comments>http://almaer.com/blog/cleanup-of-manual-animation-via-dojo-animation#comments</comments>
		<pubDate>Mon, 27 Jul 2009 20:52:54 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Bespin]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2485</guid>
		<description><![CDATA[
When posting on the Bespin Pie back in the day, I showed the Dojo animation code that we used to fake out our canvas pie animation:

var anim = dojo.fadeIn&#40;&#123;
    node: &#123; // fake it out for Dojo to think it is changing the style :)
        [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bengalbraith.files.wordpress.com/2009/05/puck_off.png?w=188&#038;h=188" align="center"></p>
<p>When posting on <a href="http://almaer.com/blog/bespin-gives-you-some-pie-and-will-do-more-web-work-for-you">the Bespin Pie</a> back in the day, I showed the Dojo animation code that we used to fake out our canvas pie animation:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> anim <span style="color: #339933;">=</span> dojo.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    node<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// fake it out for Dojo to think it is changing the style :)</span>
        style<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
    easing<span style="color: #339933;">:</span> dojo.<span style="color: #660066;">fx</span>.<span style="color: #660066;">easing</span>.<span style="color: #660066;">backOut</span><span style="color: #339933;">,</span>
&nbsp;
    onAnimate<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> progress <span style="color: #339933;">=</span> values.<span style="color: #660066;">opacity</span><span style="color: #339933;">;</span>
        renderPie<span style="color: #009900;">&#40;</span>progress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Pete Higgin&#8217;s hinted that we should cleanup this hack (asking to do the opacity and then getting the value back out) and finally (due to a weird bug in a WebKit nightly that gave me reason to poke) I cleaned it up:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> dojo._Animation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
    easing<span style="color: #339933;">:</span> dojo.<span style="color: #660066;">fx</span>.<span style="color: #660066;">easing</span>.<span style="color: #660066;">backOut</span><span style="color: #339933;">,</span>
    curve<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0.0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1.0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    onAnimate<span style="color: #339933;">:</span> renderPie
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I am sure there is an easier way too!</p>
<p>FYI, the &#8220;pie&#8221; is finally a pie menu in tip, which will make its way to a Bespin version push soon with functionality we have been dying to get in production since the initial prototype.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/cleanup-of-manual-animation-via-dojo-animation/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Having fun with Canvas, but the aim is to have to use it less and less; Performance wars move from raw JS to DOM</title>
		<link>http://almaer.com/blog/having-fun-with-canvas-but-the-aim-is-to-have-to-use-it-less-and-less-performance-wars-move-from-raw-js-to-dom</link>
		<comments>http://almaer.com/blog/having-fun-with-canvas-but-the-aim-is-to-have-to-use-it-less-and-less-performance-wars-move-from-raw-js-to-dom#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:27:51 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2459</guid>
		<description><![CDATA[
We are having a great time using Canvas for Bespin and a few other projects. Having text, images, and boxes as the primitives on the Web just isn&#8217;t good enough, so leap frogging to HTML5-land where we have the ability to arbitrarily paint pixels is fantastic. Mix this with the ability to directly manipulate video, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://almaer.com/blog/uploads/canvasbg.jpg" alt="canvasbg" title="canvasbg" width="500" height="313" class="alignnone size-full wp-image-2461" /></p>
<p>We are having a great time using Canvas for Bespin and a few other projects. Having text, images, and boxes as the primitives on the Web just isn&#8217;t good enough, so leap frogging to HTML5-land where we have the ability to arbitrarily paint pixels is fantastic. Mix this with the ability to directly manipulate video, and you have new opportunities.</p>
<p>However, Canvas also has obvious issues. How do you make it accessible? Or searchable? We have some ideas there, but they are a long way off. The goal has never been to use Canvas as the shiny toy. With Bespin, we actually tried to do it with DOM, and it wasn&#8217;t so much chutzpah as &#8220;can&#8217;t get it to perform&#8221;-pah that lead us down the path of Canvas. The usual suspects in the stack weren&#8217;t working for us, whereas others were blazing (e.g. JavaScript performance has blown us away, as has Canvas itself).</p>
<p>With major browsers like Firefox 3.5 (Safari 4, Chrome 2, etc) I am very much excited to work with browsers (say, the great Firefox team :) to kick into gear on the next level of improvements. The current batch have been competing on the performance of JavaScript. The new engines are fantastic, and really change the game on what can be done. Add in Web Workers to the magnitude speed bump of JS and Web devs can truly build responsive low-latency applications. We are now seeing improvements to the DOM, the next frontier. It is all well and good to have your JS run nice and speedy, but if the DOM can&#8217;t keep up then we are still in trouble. This is why we had to go to Canvas for Bespin in the first place!  I am hoping that we will be able to push on DOM and other APIs to get to a point where our DOM based Bespin can come back to town.</p>
<p>There is a time and a place for Canvas though. Rather than running the show, I much prefer the unobtrusive extensions that you can provide. I am also looking forward to seeing more tools that use a server side component to do some image manipulation&#8230; now work on the client through Canvas and ImageData. Vlad <a href="http://blog.vlad1.com/2009/06/22/to-sprite-or-not-to-sprite/">pondered</a> why CSS spriting tools are all server-side for example.</p>
<p>Christian Effenberger has been <a href="http://lab.netzgesta.de/">doing this kind of work</a> for a long time, and there is room for a lot more. I really like having Canvas available in more places, such as anywhere an image can be used (e.g. WebKit CSS extensions where you can use a Canvas as a background-image). That gives you full control to style something in zany ways, while still staying in DOM land. It also means that things can play together really nice. We continue to push more into CSS (transitions, gradients, etc.) and animation libraries (<a href="http://scripty2.com/">Scripty2</a> looks nice!</a>).</p>
<p><img src="http://ajaxian.com/wp-content/uploads/scripty2.png"></p>
<p>There is still much work to be done on putting the pieces together. I don&#8217;t know about you, but doing some common things with layout and UI still drive me nuts. Having the low level new tools like border-image are cool, but I really long for a tool that graphically lets me take a mock, cut it up, and build it out as a generalized component (stretches in the right place etc). The tool could then spit out more than just a border-image version, but old style divs + CSS to make it work everywhere. One tool, run output anywhere.</p>
<p><img src="http://almaer.com/blog/uploads/csstools.png" alt="csstools" title="csstools" width="500" height="335" class="alignnone size-full wp-image-2460" /></p>
<p>So, time to take a breath, take a look at what bleeding edge folk are doing to get rich experiences, and push it into the core platform itself. This will mean less Canvas, but used in the right places, and we will move down the stack again. If we don&#8217;t push use cases down into the core, then we are doomed to stagnate or fork the Web.</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/having-fun-with-canvas-but-the-aim-is-to-have-to-use-it-less-and-less-performance-wars-move-from-raw-js-to-dom/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Icky? Using strings to add legacy features in languages</title>
		<link>http://almaer.com/blog/icky-using-strings-to-add-legacy-features-in-languages</link>
		<comments>http://almaer.com/blog/icky-using-strings-to-add-legacy-features-in-languages#comments</comments>
		<pubDate>Tue, 26 May 2009 16:05:59 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2419</guid>
		<description><![CDATA[
A contingent in the JavaScript community is pretty much solely focused on securing the language. Security is always important, but even more-so when you are dealing with a language that runs in a user agent to run the Web.
Whenever you try to add a feature to a language you are instantly dealing with legacy and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://almaer.com/blog/uploads/strings.jpg" alt="strings" title="strings" width="500" height="333" class="alignnone size-full wp-image-2422" /></p>
<p>A contingent in the JavaScript community is pretty much solely focused on securing the language. Security is always important, but even more-so when you are dealing with a language that runs in a user agent to run the Web.</p>
<p>Whenever you try to add a feature to a language you are instantly dealing with legacy and backwards compatibility.</p>
<p>Perl has a strict mode that is very popular in the community. I remember projects where if I checked in a module without <code>use strict;</code> and <code>-w</code> I would get beaten up.</p>
<p>Back to JavaScript, how can we apply stricter rules on what we do in the JavaScript runtime after the face? One solution that the ECMAScript Edition 5 folks came up with is borrowing <code>use strict</code> but since they couldn&#8217;t add it to the language itself, they have you put it in a string <code>"use strict";</code>. You can place it at the top of the file, or even as the first statement in a function.</p>
<p>I find it incredibly ugly, yet pragmatic. It works.</p>
<p>However, then I saw some new items:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;use strict,cajita&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And currently you can&#8217;t switch the order around? It looks for absolute keys? That seems a little crazy. Surely all of these should be possible:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;use cajita,strict&quot;</span><span style="color: #339933;">;</span>
<span style="color: #3366CC;">&quot;use strict,cajita&quot;</span><span style="color: #339933;">;</span>
<span style="color: #3366CC;">&quot;use strict&quot;</span><span style="color: #339933;">;</span>
<span style="color: #3366CC;">&quot;use cajita&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then this little pragmatic hack starts to get real messy. I start to joking imagine a ludicrous world like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;use strict&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #3366CC;">&quot;use let&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// let's get let in there!</span>
  <span style="color: #3366CC;">&quot;use cramda&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// I love Alex's cramda, let me use it!</span>
  <span style="color: #3366CC;">&quot;use e4x&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// XML inline. Screw templates</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// If I see a var with the same name, REALLY use let instead</span>
  <span style="color: #3366CC;">&quot;let x;&quot;</span>
  <span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Now I can use the cramda</span>
  <span style="color: #3366CC;">&quot;x = #(a, b) { &quot;</span>\
  <span style="color: #3366CC;">&quot; ... logic here ... &quot;</span>\
  <span style="color: #3366CC;">&quot;};&quot;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// And the let... ironic that it is in a string now</span>
  <span style="color: #3366CC;">&quot;let y = &lt;xml&gt;&lt;/xml&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Annotations come to JavaScript!</span>
  <span style="color: #3366CC;">&quot;@Serializable&quot;</span>
  <span style="color: #003366; font-weight: bold;">function</span> someThing<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I like to think of myself as pragmatic, but why do I feel so cranky about <code>"use strict";</code>? :)</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/icky-using-strings-to-add-legacy-features-in-languages/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Write Once, Pwn Everywhere&#8230;. oh and Jetpacking around</title>
		<link>http://almaer.com/blog/write-once-pwn-everywhere-oh-and-jetpacking-around</link>
		<comments>http://almaer.com/blog/write-once-pwn-everywhere-oh-and-jetpacking-around#comments</comments>
		<pubDate>Thu, 21 May 2009 00:37:33 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[jetpack]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2417</guid>
		<description><![CDATA[
By now you have probably read about the critical Java vulnerability and how easy it is to take over a machine from a web page via a Java applet.
Apparently, Sun fixed it fairly quickly, but even then some people say their fix was too specific and thus there are still problems. Apple on the other [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" src="http://toonlet.com/embed/strip?i=27722"></script></p>
<p>By now you have probably read about the <a href="http://landonf.bikemonkey.org/code/macosx/CVE-2008-5353.20090519.html">critical Java vulnerability</a> and how <a href="http://blog.cr0.org/2009/05/write-once-own-everyone.html">easy it is to take over a machine</a> from a web page via a Java applet.</p>
<p>Apparently, Sun fixed it fairly quickly, but even then some people say their fix was too specific and thus there are still problems. Apple on the other hand, were not diligent and are still yet to provide a fix. Ouch.</p>
<p>Painful news as JavaOne approaches and Sun tries to push JavaFX. I was trying to think of a Java applet that I have used (knowingly) in the recent past, and I think the only candidate is the Facebook photo uploader.</p>
<p>I have been watching some research for a talk on JavaFX and I am really torn. In theory, the Java platform is phenomenal and should be a great choice for doing this kind of development. The scene graph work in JavaFX is very nicely done, but the implementation seems to be a touch off in much of what I have seen. Scrolling causing the applet to go blank? Browser crashes? Ouch. But, JavaFX is new, and has a chance to get better. Their problem is that they are squeezed from both sides. The browser platform itself is accelerating quickly, and it has the advantage of being native. Once you go to plugin land you are competing with Flash with its large share and proven ability.</p>
<p><b>Getting webby</b></p>
<p><img src="https://jetpack.mozillalabs.com/images/Jetpack_logo.png"></p>
<p>I find myself wanting to get more and more webby. This is why I was excited to work with the <a href="http://labs.mozilla.com/2009/05/introducing-jetpack-call-for-participation/">Jetpack project</a> that we just launched today at Mozilla Labs. Being able to extend the browser using Web technology itself is going to open the door for more playing. People have created 7000 addons for Firefox alone, but as someone who has done a touch of XUL, I am happy to stay in my familiar territory of HTML, CSS, JS. Jetpack has just been born, and is incredibly early stage, but I can&#8217;t wait to see it grow and get the APIs that people want in a secure extensible model.</p>
<p>You will see a lot of Bespin in there too. Below is a screencast where I create a Jetpack feature on the fly (no reloads!) using Bespin, and once you install Jetpack it embeds the puppy into the tutorial and the developer area too. Much more than can be done though!</p>
<p><object width="480" height="276"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4721680&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=01AAEA&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4721680&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=01AAEA&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="480" height="276"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/write-once-pwn-everywhere-oh-and-jetpacking-around/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Browser storage: Do we need SQL? Or would a JSON approach be better?</title>
		<link>http://almaer.com/blog/browser-storage-do-we-need-sql-or-would-a-json-approach-be-better</link>
		<comments>http://almaer.com/blog/browser-storage-do-we-need-sql-or-would-a-json-approach-be-better#comments</comments>
		<pubDate>Fri, 10 Apr 2009 17:56:05 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2372</guid>
		<description><![CDATA[

Ian Hickson: &#8220;I expect I’ll be reverse-engineering SQLite and speccing that, if nothing better is picked first. As it is, people are starting to use the database feature in actual Web apps (e.g. mobile GMail, iirc).&#8221;

When I read that comment to Vlad&#8217;s post on HTML 5 Web Storage I gulped. This would basically make SQLite [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://almaer.com/blog/uploads/jsondata.jpg" alt="jsondata" title="jsondata" width="500" height="375" class="alignnone size-full wp-image-2373" /></p>
<blockquote><p>
Ian Hickson: &#8220;I expect I’ll be reverse-engineering SQLite and speccing that, if nothing better is picked first. As it is, people are starting to use the database feature in actual Web apps (e.g. mobile GMail, iirc).&#8221;
</p></blockquote>
<p>When I read that comment to Vlad&#8217;s <a href="http://blog.vlad1.com/2009/04/06/html5-web-storage-and-sql/">post on HTML 5 Web Storage</a> I gulped. This would basically make SQLite the HTML 5 for storage in the browser. You would have to be a little crazy to re-write the exact semantics (including bugs) of SQLite and its dialect. What if you couldn&#8217;t use the public domain code?</p>
<p>Gears lead out strong with making a relational database part of the toolbox for developers. It embedded its own SQLite, in fact one that was customized to have the very cool <a href="http://code.google.com/apis/gears/api_database.html">full text search</a> ability. However, this brings up the point of &#8220;which SQLite do you standardize on?&#8221;</p>
<p>The beauty of using SQL and SQLite is that many developers already know it. RDBMS has been mainstream for donkey&#8217;s years; we have tools to manage SQL, to view the model, and to tweak for performance. It has gone through the test of time.</p>
<p>However, SQL has always been at odds with many developers. Ted Neward brought up ORM as the <a href="http://stackoverflow.com/questions/404083/is-orm-still-the-vietnam-of-computer-science">vietnam of computer science</a> (which is going a touch far ;). I was just lamenting with a friend at Microsoft on how developers spend 90% of their time munging data. Our life is one of transformations, and that is why I am interested in a world of JavaScript on client and server AND database. We aren&#8217;t there yet, but hopefully we can <a href="https://wiki.mozilla.org/ServerJS">make progress</a>.</p>
<p>One of Vlad&#8217;s main questions is &#8220;Is SQL the right API for Web developers?&#8221; and it is a valid one. I quickly found that for most of my tasks with the DB I just wanted to deal with JSON and hence created a wrapper <a href="http://almaer.com/blog/gearsdb-a-simple-abstraction-for-the-google-gears-database">GearsDB</a> to let me insert/update/select/delete the database with a JSON view of the world. You probably wouldn&#8217;t want to do this on large production applications for performance reasons, but it works well for me.</p>
<p>Now a days, we have interesting APIs such as <a href="http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/">JSONQuery</a> which <a href="http://sitepen.com/labs/persevere.php">Persevere</a> (and other databases) use. I would love to see Firefox and other browsers support something like this and let us live in JSON throughout the stack. It feels so much more Webby, and also, some of the reasons that made us stay with SQL don&#8217;t matter as much in the client side world. For example, when OODBMS took off in some Enterprises, I remember having all of these Versant to Oracle exports just so people could report on the darn data. On the client the database is used for a very different reason (local storage) so lets use JSON!</p>
<p>That being said, at this point there are applications such as Gmail, MySpace search, Zoho, and many iPhone Web applications that use the SQL storage in browsers. In fact, if we had the API in Firefox I would have Bespin using it right now! We had a version of this that abstracted on top of stores, but it was a pain. I would love to just use HTML 5 storage and be done.</p>
<p>So, I think that Firefox should actually support this for practical reasons (and we have SQLite right there!) but should push JSON APIs and let developers decide. I hope that JSON wins, you? I also hope that Hixie doesn&#8217;t have to spec SQLite :/</p>
<p><b>Related</b><br />
It was also interesting to just read this post <a href="http://intertwingly.net/blog/2009/04/09/Abusing-Web-Storage">Abusing Web Storage</a> via Sam Ruby:</p>
<blockquote><p>
<a href="http://www.securityfocus.com/archive/107/494548/30/150/threaded">Alberto Trivero</a>: The aim of this <a href="http://trivero.secdiscover.com/html5whitepaper.pdf">white paper</a> is to analyze security implications of the new HTML 5 client-side storage technology, showing how different attacks can be conduct in order to steal storage data in the client’s machine.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/browser-storage-do-we-need-sql-or-would-a-json-approach-be-better/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
