<?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>Brit Gardner ::: Web Developer ::: Dallas, TX &#187; javascript</title>
	<atom:link href="http://britg.com/tags/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://britg.com</link>
	<description>The big yellow one&#039;s the sun.</description>
	<lastBuildDate>Sun, 10 Jan 2010 17:25:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quick Look: WebGL and Web Sockets</title>
		<link>http://britg.com/2010/01/10/quick-look-webgl-and-web-sockets/</link>
		<comments>http://britg.com/2010/01/10/quick-look-webgl-and-web-sockets/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 17:07:11 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[webgl]]></category>
		<category><![CDATA[websockets]]></category>

		<guid isPermaLink="false">http://britg.com/?p=1303</guid>
		<description><![CDATA[The internet is still a very young ecosystem of immature techn&#8230; Woah, the BS meter pegged there for a second.  Forget the pontification, let me just spit out the two technologies that get me excited about billing myself as a Web Developer.
WebGL
This is a new spec that&#8217;s being developed by the Khronos Group (the [...]]]></description>
			<content:encoded><![CDATA[<p><strike>The internet is still a very young ecosystem of immature techn&#8230;</strike> Woah, the BS meter pegged there for a second.  Forget the pontification, let me just spit out the two technologies that get me excited about billing myself as a Web Developer.</p>
<h3>WebGL</h3>
<p>This is a new spec that&#8217;s being developed by the <a href="http://www.khronos.org/webgl/">Khronos Group</a> (the group behind OpenGL) to expose OpenGL to browsers through the canvas element.</p>
<p>Why is it exciting? Three words: <strong>Javascript</strong>. <strong>Hardware</strong>. <strong>Acceleration</strong>.  Damn, I need three more: <strong>In</strong>. <strong>The</strong>. <strong>Browser</strong>.</p>
<p>The concepts should speak for themselves, but if you still need some convincing follow the steps below and be sure to take a look at your CPU usage while running these demos.  (Hint: CPU usage will be very low because you&#8217;re riding your GPU).</p>
<ul>
<li>Grab the latest nighly of Chromium <a href="http://build.chromium.org/buildbot/snapshots/chromium-rel-xp/?C=M;O=D">here</a> if you are not already running it.</li>
<li>Start Chromium via the command line:
<ul>
<li>Windows: <code>chrome.exe --no-sandbox --enable-webgl</code></li>
<li>OSX: <code>Chromium.app/Contents/MacOS/Chromium --no-sandbox --enable-webgl</code></li>
<li>Linux: <code>./chrome --no-sandbox --enable-webgl</code></li>
</ul>
</li>
<li>Follow <a href="http://hacks.mozilla.org/2009/09/three-more-webgl-demos/">this link</a> to some examples of WebGL in action.</li>
</ul>
<p>Again, check your CPU usage while running the demos. It should be very low (if you have a GPU) as the demos should be hardware accelerated.</p>
<h3>Web Sockets</h3>
<p>Comet? Long-Polling? Forever Frame? In two years we will all be sitting around a trash barrel fire laughing about the days of yore when we had to use such hacks. </p>
<p>Why are we huddled around a trash barrel fire? Because it&#8217;s post-apocolyptic New Zealand, the last bastion of humanity. Anyways, that&#8217;s another &#8220;In This Decade&#8221; blog post&#8230;</p>
<p>From <a href="http://www.websockets.org/">websockets.org</a>:</p>
<blockquote><p>[The Web Socket Interface] defines a full-duplex communications channel that operates over a single socket and is exposed via a JavaScript interface in compliant browsers</p></blockquote>
<p>Here&#8217;s the <a href="http://www.w3.org/TR/2009/WD-websockets-20091222/">spec</a> in case you want to read it&#8230; haha, me neither.</p>
<p>Again, the concept here should speak for itself.  Two-way communication with web servers in an easy-to-use interface.</p>
<pre class="brush: jscript;">

var websock = new WebSocket(&quot;ws://www.websocket.org&quot;);

websock.onopen = function(evt) {
  console.log(evt)
  websock.send(&quot;Hello Web Socket!&quot;);
};
websock.onmessage = function(evt) {
  console.log(evt)
};
websock.onclose = function(evt) {
  console.log(evt)
};
websock.close();
</pre>
<p>Fortunately, there are already many projects implementing the web sockets protocol.  To name a few,</p>
<ul>
<li><a href="http://github.com/guille/node.websocket.js/">node.websocket.js</a></li>
<li><a href="http://github.com/igrigorik/em-websocket">em-websocket (Ruby)</a></li>
<li><a href="http://code.google.com/p/pywebsocket/">pywebsocket</a></li>
</ul>
<p>One thing to note is that the web socket protocol will adhere to the cross-domain security restriction that XHR has.  The good news is it will ship with support for server-side origin discretion using the same Origin headers in <a href="http://britg.com/2009/12/02/cross-origin-resource-sharing/">CORS</a>.</p>
<h3>It&#8217;s all about the gaming, stupid</h3>
<p>I&#8217;m going to predict that in 2 years, we will see current A quality games developed in-browser ontop of these two technologies.  Don&#8217;t get me wrong, AAA quality console and PC titles won&#8217;t be disrupted like the music and print industries any time soon.  But, the &#8220;casual&#8221; label on browser games will go away.</p>
<p>This is what has me really excited about being a web developer in this decade.  Parity with desktop development is inching closer, and all ontop of open technologies.</p>
<p>No plugins.  No corporate owner.</p>
<p>Win. Win.</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2010/01/10/quick-look-webgl-and-web-sockets/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Cross Origin Resource Sharing with Sinatra</title>
		<link>http://britg.com/2009/12/29/cross-origin-resource-sharing-with-sinatra/</link>
		<comments>http://britg.com/2009/12/29/cross-origin-resource-sharing-with-sinatra/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 15:46:45 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[cors]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://britg.com/?p=1282</guid>
		<description><![CDATA[It&#8217;s no lie that I think highly of the potential of Cross Origin Resource Sharing.  One of the great things about it is that it doesn&#8217;t take much re-wiring of existing server (or client-side) apps to start working cross domain.
Enabling your server app is as simple as including a few extra headers when you [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s no lie that <a href="http://britg.com/2009/12/02/cross-origin-resource-sharing/">I think highly</a> of the potential of Cross Origin Resource Sharing.  One of the great things about it is that it doesn&#8217;t take much re-wiring of existing server (or client-side) apps to start working cross domain.</p>
<p>Enabling your server app is as simple as including a few extra headers when you detect a cross origin request.  How do you know it&#8217;s a cross origin request?  You&#8217;ll see the <code>Origin:</code> header &#8212; all CORS requests will have it.  From there, response headers depend on the specifics of the request, but I won&#8217;t go over those here &#8212; check out the <a href="https://developer.mozilla.org/En/HTTP_access_control">Mozilla Developer Center treatment</a> for in-depth information.</p>
<p>I&#8217;ve been working with Sinatra a lot lately, so I put together <a href="http://github.com/britg/sinatra-cross_origin">an extension for Sinatra</a> that makes enabling Cross Origin requests even easier.</p>
<p><code>sudo gem install sinatra-cross_origin</code></p>
<p>There are two ways to use the extension: globally or per-route.</p>
<h3>Global</h3>
<p>For when you want to share all your endpoints cross-domain.</p>
<pre class="brush: ruby;">

require 'sinatra/base'
require 'sinatra/cross_origin'

class MyApp &lt; Sinatra::Base
  register Sinatra::CrossOrigin

  enable cross_origin

  get '/' do
    &quot;This is available to cross domain javascript requests automatically&quot;
  end
end
</pre>
<h3>Per Route</h3>
<p>For when you want to share only some of your routes cross-domain.</p>
<pre class="brush: ruby;">

require 'sinatra/base'
require 'sinatra/cross_origin'

class MyApp &lt; Sinatra::Base
  register Sinatra::CrossOrigin

  get '/' do
    cross_origin
    &quot;This is available to cross domain javascript requests&quot;
  end
end
</pre>
<h3>Configuration</h3>
<p>You can mix and match app-wide config and request specific config.</p>
<pre class="brush: ruby;">

require 'sinatra/base'
require 'sinatra/cross_origin'

class MyApp &lt; Sinatra::Base
  register Sinatra::CrossOrigin

  configure do
    # Comma separate list of remote hosts that are allowed.
    # :any will allow any host
    set :allow_origin, :any

    # HTTP methods allowed
    set :allow_methods, [:get, :post]

    # Allow cookies to be sent with the requests
    set :allow_credentials, true
  end

  get '/' do
    # Only available to GET requests originating from
    # http://example.com.  No cookies allowed.
    cross_origin :allow_origin =&gt; 'http://example.com',
      :allow_methods =&gt; [:get],
      :allow_credentials =&gt; false
    &quot;This is available to cross domain javascripts&quot;
  end
end
</pre>
<p>Grab the source at Github: <a href="http://github.com/britg/sinatra-cross_origin">britg/sinatra-cross_origin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/12/29/cross-origin-resource-sharing-with-sinatra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scriptstack &#8211; Organize and Share Javascripts</title>
		<link>http://britg.com/2009/12/17/scriptstack-organize-and-share-javascripts/</link>
		<comments>http://britg.com/2009/12/17/scriptstack-organize-and-share-javascripts/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 05:11:57 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[featured]]></category>

		<guid isPermaLink="false">http://britg.com/?p=1263</guid>
		<description><![CDATA[I&#8217;ve been hacking on a small project in my free time that I uploaded today: scriptstack.
What is scriptstack?
Well, if you&#8217;re like me you probably have 4 or 5 javascript files you include in just about every new project or site your start.  jQuery.  Tooltips.  Lightbox. qTip. Or, you just put together a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://scriptstack.com"><img src="http://britg.com/blog/wp-content/uploads/2009/12/scriptstack.png" alt="scriptstack" title="scriptstack" width="163" height="36" class="alignright size-full wp-image-1266" /></a>I&#8217;ve been hacking on a small project in my free time that I uploaded today: <a href="http://scriptstack.com">scriptstack</a>.</p>
<h3>What is scriptstack?</h3>
<p>Well, if you&#8217;re like me you probably have 4 or 5 javascript files you include in just about every new project or site your start.  jQuery.  Tooltips.  Lightbox. <a href="http://britg.com/2009/12/06/qtip-jquery-tooltip-plugin-with-excellent-docs/">qTip</a>. Or, you just put together a nice portfolio site for a client and you want to save that specific set of javascript plugins for the next time you do something similar.</p>
<p>Scriptstack aims to be an easy and social way to organize your &#8220;stacks&#8221; of scripts.  You can:</p>
<ul>
<li>Upload scripts.</li>
<li>Click and drag them into the order they should be loaded in the browser.</li>
<li>Tag them with a few keywords to make them indexable for future search.</li>
<li>Download the concatenated stack in minified or raw format.</li>
</ul>
<p>That&#8217;s about it for now, haha. Release early, release often, right?  I should note that there&#8217;s no permissions on the stacks.  If you create one, it&#8217;s editable by anyone right now.  I plan to add User accounts and ownership soon.</p>
<p><strong>Warning:</strong> the site probably only works in Firefox.</p>
<h3>Under the hood</h3>
<p>I took this opportunity to expand my horizons as far as the technology under the hood.  I&#8217;ll go in-depth on these as I continue to develop, but a quick rundown of the tech stack (<em>pun intended but probably shouldn&#8217;t be</em>):</p>
<ul>
<li><a href="http://mongodb.org">MongoDB</a> (via <a href="http://mongohq.com">MongoHQ</a>)</li>
<li><a href="http://github.com/jnunemaker/mongomapper">MongoMapper</a></li>
<li><a href="http://heroku.com">Heroku</a></li>
<li><a href="http://sinatrarb.com">Sinatra</a></li>
<li><a href="http://haml-lang.com">Haml</a></li>
<li><a href="http://compass-style.org/">Compass</a></li>
</ul>
<p>I also open sourced all the code that runs the site <a href="http://github.com/britg/scriptstack">here</a> incase you are interested in what poorly written Ruby looks like.</p>
<p>If you happen to check it out, let me know what you think!  And as I said, I will expand on different parts of it here in the near future, so stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/12/17/scriptstack-organize-and-share-javascripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Uploading Plus JSON Response Plus JSONView = Disaster</title>
		<link>http://britg.com/2009/12/11/ajax-uploading-plus-json-response-plus-jsonview-disaster/</link>
		<comments>http://britg.com/2009/12/11/ajax-uploading-plus-json-response-plus-jsonview-disaster/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 04:17:51 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax upload]]></category>
		<category><![CDATA[jsonview]]></category>

		<guid isPermaLink="false">http://britg.com/?p=1249</guid>
		<description><![CDATA[So, I&#8217;ve spend the last few hours debugging what seemed to be a tear in the fabric of the universe.  I&#8217;m working this excellent javascript library, AjaxUpload, that, as the name implies, creates a no-pageload form upload.  It&#8217;s easy to implement and makes an upload infinitely more usable in my opinion; definitely check [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve spend the last few hours debugging what seemed to be a tear in the fabric of the universe.  I&#8217;m working this excellent javascript library, <a href="http://valums.com/ajax-upload/">AjaxUpload</a>, that, as the name implies, creates a no-pageload form upload.  It&#8217;s easy to implement and makes an upload infinitely more usable in my opinion; definitely check it out.</p>
<p>The upload works by pointing the <code>target</code> attribute of a multipart form at a hidden iframe.  When the iframe updates with the results of the upload, an event listener reports the response to the parent page, and voila &#8212; you have an upload without a page refresh.</p>
<p>The only problem with this iframe approach is that your response is being fully rendered by the browser instead of passed in the response body of an XMLHttpRequest like most ajax interactions.  Combine this with a server-side upload script that returns JSON and here&#8217;s where the fun starts.  </p>
<p>If you&#8217;re using the <a href="https://addons.mozilla.org/en-US/firefox/addon/10869">JSONView</a> Firefox plugin (and why the hell aren&#8217;t you!?) the JSON gets rendered with some wrapper html and styling to create an interactive and human readable version of the JSON.</p>
<p>See the problem here?  What gets reported to your upload-complete event listener isn&#8217;t the original JSON, but the HTML-wrapped JSON.  This can lead to what can only be described as multiple hours of FAIL in which you try and figure out why your JSON response can&#8217;t be parsed and used in your javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/12/11/ajax-uploading-plus-json-response-plus-jsonview-disaster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Origin Resource Sharing &#8211; AKA The Holy Grail</title>
		<link>http://britg.com/2009/12/02/cross-origin-resource-sharing/</link>
		<comments>http://britg.com/2009/12/02/cross-origin-resource-sharing/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 13:10:23 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[cors]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[XHR]]></category>

		<guid isPermaLink="false">http://britg.com/?p=1106</guid>
		<description><![CDATA[Cross Origin Resource Sharing (CORS) is an emerging spec from the W3C that allows for cross-site XMLHTTPRequests.]]></description>
			<content:encoded><![CDATA[<p>The other day I was chatting with a guy about the overly restrictive <a href="http://en.wikipedia.org/wiki/Same_origin_policy">cross-domain request policy</a> and how silly it is given the pervasiveness of cross-domain apps on the web today. Most devs get around this restriction with hacks like jsonp or nested iframes anyways.  I told him that it&#8217;s high time we move past this archaic security measure and take web apps to the next level!</p>
<p>He just said, &#8220;Uh&#8230; do you want to upgrade your coffee to a venti for only 35 cents more?&#8221;  Always the salesman that guy&#8230;</p>
<h3>Cross Origin Resource Sharing</h3>
<p>Recently I stumbled across <a href="http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/">this article</a> on the excellent <a href="http://hacks.mozilla.org/">Mozilla Hacks</a> blog.  Cross Origin Resource Sharing (CORS). Sweet!  Finally a <em>true</em> implementation of cross-site XMLHttpRequests.</p>
<blockquote><p>The CORS standard works by adding new HTTP headers that allow servers to serve resources to permitted origin domains.</p></blockquote>
<p>They&#8217;re getting everything right with this one:</p>
<ul>
<li>it&#8217;s completely opt-in server-side, so browsers can implement CORS without opening up a bunch of security holes,</li>
<li>it uses the existing XMLHttpRequest object so current code can easily start working cross-domain,</li>
<li>and it&#8217;s totally transparent to the client-side developer &#8212; validation, pre-flighting, and access control is all handled within the XMLHttpRequest object without any additional code!</li>
</ul>
<p>Apparently it&#8217;s been in the works at the W3C for a couple of years (formerly known as &#8216;<a href="http://dev.w3.org/2006/waf/access-control/">Access Control</a>&#8216;). But only the most recent versions of Firefox and webkit based browsers are starting to support it.  Of course Microsoft, in their infinite wisdom, decided it would be best to implement their own spec, <a href="http://msdn.microsoft.com/en-us/library/cc288060%28VS.85%29.aspx">XDomainRequest</a>.  Some things never change&#8230;</p>
<h3>The Holy Grail</h3>
<p><div id="attachment_1114" class="wp-caption alignright" style="width: 160px"><img src="http://britg.com/blog/wp-content/uploads/2009/12/holy-grail-150x150.jpg" alt="Not the knights who say Ni" title="holy-grail" width="150" height="150" class="size-thumbnail wp-image-1114" /><p class="wp-caption-text">Not the knights who say Ni</p></div>Is this a big deal?  I&#8217;m going to go out on a limb here and say this is the holy grail of web development!</p>
<p>Why?  For one, there isn&#8217;t a good, non flash-based way to implement cross-domain long-polling/comet.  If there&#8217;s one thing that&#8217;s going to define the next generation of the web, it&#8217;s real-time apps.  CORS enables efficient real-time &#8220;mashups&#8221; (hate that term) that don&#8217;t rely on iframe hacks or flash.</p>
<p>Psh&#8230; cross-domain, real-time? Nothing more than a niche application, right?  Not so fast.  </p>
<p>The web will soon (if not already) start its industrial revolution.  A &#8220;building up&#8221; versus the &#8220;building out&#8221; if you will.  New web development will progressively become based around existing sites, rather than the creation of new sites.  A true cross-domain solution is vitally important to this.  </p>
<p>No, no, I&#8217;m not saying that people will stop creating new sites &#8212; that will always happen.  I&#8217;m saying startups will turn more and more to building apps targeted at sites users are already invested in instead of trying to get them to some new property.  </p>
<p>Examples:</p>
<ul>
<li>The <a href="http://disqus.com">Disqus</a> comment app on this blog.</li>
<li>The <a href="http://business.meebo.com/publishers/">Meebo Bar</a></li>
<li>Those little &#8216;Feedback&#8217; widgets you see all over sites now.</li>
</ul>
<p>A new ecosystem is emerging: apps built with web technologies that run on other sites.  But they&#8217;re mostly iframe based with all the restrictions that iframes have (no access to the DOM, slow, etc).  With CORS, developers can almost seemlessly develop apps cross-domain with all the power of same-domain scripting, making it the most important development to come along since the XMLHttpRequest!</p>
<p>In future posts I&#8217;ll delve into this &#8220;industrial revolution&#8221; of the web, but for now&#8230; back to that grail.</p>
<p><object width="445" height="364"><param name="movie" value="http://www.youtube.com/v/fIXByCAIzos&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6&#038;border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/fIXByCAIzos&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6&#038;border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/12/02/cross-origin-resource-sharing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Server Side Javascript Continued &#8211; Node.js (plus example)</title>
		<link>http://britg.com/2009/07/01/server-side-javascript-continued-node-js-plus-example/</link>
		<comments>http://britg.com/2009/07/01/server-side-javascript-continued-node-js-plus-example/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 13:00:50 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[comet]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[long-polling]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[server-side javascript]]></category>

		<guid isPermaLink="false">http://britg.com/?p=1025</guid>
		<description><![CDATA[Node's goal is to provide an easy way to build scalable network programs. ... Each connection is only a small heap allocation. This is in contrast to today's more common model where OS threads are employed for concurrency.]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> <em>Node&#8217;s APIs have change quite a bit since this post was made.  Check out the latest stuff at <a href="http://nodejs.org">nodejs.org</a>!</em></p>
<p>In my <a href="http://britg.com/2009/06/08/the-brave-new-world-of-server-side-javascript/">previous post on server-side javascript</a> (SSJ) I took a quick look at <a href="http://jackjs.org/">Jack</a>, a project that aims to implement the Rack/WSGI pattern for javascript. I still think this approach is great as it opens the door for more traditional Rails/Django-esque frameworks for SSJ.</p>
<p>But, lets face it, the next gen web is all about real-time interactivity, and current popular environments and servers just aren&#8217;t ideal for that.  It&#8217;s not their fault, up until recently we only cared about getting that request handled and out the door as quickly as possible with nothing shared between requests.  Unfortunately, it&#8217;s no longer just about number of requests/sec &#8212; we now need high concurrency, long-lasting connections, and shared persistence over these connections.</p>
<h3>Node.js</h3>
<p>Enter <a href="http://tinyclouds.org/node/">node.js</a> &#8211; a high performance javascript project built ontop of Google&#8217;s V8 runtime.  From the author&#8217;s description:</p>
<blockquote><p>Node&#8217;s goal is to provide an easy way to build scalable network programs. &#8230; Each connection is only a small heap allocation. This is in contrast to today&#8217;s more common model where OS threads are employed for concurrency.</p></blockquote>
<p>Nice, but does this pan out in implementation?  After spending a few days with Node, I truly believe that this will be the go-to project for the future of the real-time web.</p>
<h3>A Simple Game Lobby</h3>
<p>Let&#8217;s take a look at a simple example I put together.  The following is a very basic game lobby that is based on a more complex project I&#8217;m working on with node.  (You can checkout this script from <a href="http://github.com/britg/node-simple-lobby/tree/master">github</a> as well).</p>
<p>The script accepts new players through a url like <code>/join?player=joebob</code>.  Then, the client can long-poll the URL <code>/wait</code> and receive a notification in real-time when new players join!</p>
<p>First, lets define a couple of Arrays that will hold our persistence in-memory.</p>
<pre class="brush:js">// our in-memory list of player
var players = [];

// our in-memory list of players waiting
var waiting = [];</pre>
<p>Next, lets define a set of URLs our server will respond to.  Notice that the <code>/wait</code> response does not take place immediately.   Instead, the response is captured in a callback function that is held in-memory until it is called.  These callbacks are called whenever a new player hits the <code>/join</code> URL.</p>
<pre class="brush: jscript;">// define a set of paths that respond to requests
var paths = {

  /**
   * Requests to /join add players to our
   * player list, and fire off a notification
   * to all our waiting players
   **/
  &quot;/join&quot;: function(req, res) {

    // extract the player from the request
    var newPlayer = req.uri.params.player;

    // respond to this request with a list of players
    // already in the lobby
    server.respond(200, players);

    // add this player to list of players
    players.push(newPlayer);

    // notify all of our waiting players that
    // a new player has joined
    while(waiting.length &amp;gt; 0) {
      waiting.shift().callback.apply(this, [newPlayer]);
    }
  },

  /**
   * Requests to /wait holds the connection
   * open until another player joins
   **/
  &quot;/wait&quot;: function(req, res) {

    // define our waiting player and the notification
    // callback to trigger when another player joins
    var waitingPlayer = {
      &quot;player&quot;: req.uri.params.player,
      &quot;callback&quot;: function(newPlayer) {
         server.respond(200, newPlayer);
       }
    };

    waiting.push(waitingPlayer);
  }
};</pre>
<p>Finally, we define our server.  We tell the server to map requests to the paths we defined above, and to listen on port 8000.</p>
<pre class="brush: jscript;">// Define a new HTTP Server
var server = node.http.createServer(function (req, res) {

  // tell our server to look at the paths definition above
  // for a responder to the request
  paths[req.uri.path].apply(this, [req, res]);

  // respond to a request
  function respond(status, obj) {
    var body = JSON.stringify(obj);
    res.sendHeader(status, [ [&quot;Content-Type&quot;, &quot;text/json&quot;]
                         , [&quot;Content-Length&quot;, body.length]
                         ]);
    res.sendBody(body);
    res.finish();
  }
});
server.listen(8000);
puts(&quot;The game lobby has started!&quot;);</pre>
<p>To run the script, first <a href="http://tinyclouds.org/node/#download">download and build node</a>, and then <a href="http://github.com/britg/node-simple-lobby/tree/master">download this script</a> from my repo.  Execute the script with:</p>
<p><code>&gt; node gamelobby.js</code></p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/07/01/server-side-javascript-continued-node-js-plus-example/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Using a Location Proxy for URL Bindings in the Sammy Javascript Framework</title>
		<link>http://britg.com/2009/05/25/using-a-location-proxy-for-url-bindings-in-the-sammy-javascript-framework/</link>
		<comments>http://britg.com/2009/05/25/using-a-location-proxy-for-url-bindings-in-the-sammy-javascript-framework/#comments</comments>
		<pubDate>Mon, 25 May 2009 06:21:19 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[sammy]]></category>

		<guid isPermaLink="false">http://britg.com/?p=904</guid>
		<description><![CDATA[As I hinted in my previous post, the Sammy javascript framework is a great organization layer ontop of javascript heavy apps because it brings web developers back to familiar ground &#8211; the URL.  But, there are occasions where we don&#8217;t want the actual URL in the browser to change, including the hash parameters.
Why?  [...]]]></description>
			<content:encoded><![CDATA[<p>As I hinted in my <a href="http://britg.com/2009/05/18/the-return-of-the-href-the-sammy-javascript-microframework/">previous post</a>, the Sammy javascript framework is a great organization layer ontop of javascript heavy apps because it brings web developers back to familiar ground &#8211; the URL.  But, there are occasions where we don&#8217;t want the actual URL in the browser to change, including the hash parameters.</p>
<p>Why?  Maybe we don&#8217;t want Back-button accessibility, or as in my case, we are running our scripts on a 3rd party domain and we want to minimize our impact.</p>
<p>So, how can we maintain the organization that URLs provide, but prevent the actual URL from changing?  Use a proxy!</p>
<p>You can find my fork of the Sammy project <a href="http://github.com/britg/sammy/tree/master">here</a>.</p>
<h3>Usage</h3>
<pre class="brush:js">
var app = $.sammy(function(){ with(this) {

  // denote that we will be using a location proxy
  use_location_proxy = true;

  get('#/home', function() {
    //... do something
  });

  //...
});</pre>
<p>And the corresponding link would look like:</p>
<pre class="brush: xml;">
&lt;a onclick=&quot;app.setLocation('#/home'); return false;&quot; href=&quot;#/home&quot;&gt;Home&lt;/a&gt;</pre>
<p>Even though we are preventing the URL from changing in the browser (with return false), the Sammy framework still activates the &#8216;#/home&#8217; routing.</p>
<p>Some things to note:  if you define <code>use_location_proxy</code> in your application, it will no longer listen to the browser URL.  Future versions may have more flexibility with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/05/25/using-a-location-proxy-for-url-bindings-in-the-sammy-javascript-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Great, Another Internet Explorer</title>
		<link>http://britg.com/2009/01/27/great-another-internet-explorer/</link>
		<comments>http://britg.com/2009/01/27/great-another-internet-explorer/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 18:04:07 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://britg.com/?p=758</guid>
		<description><![CDATA[Just saw an article on ZDNet in which they benchmark the javascript performance of IE8 RC1 with other browsers.  Sadly, it looks like Microsoft&#8217;s javascript engine doesn&#8217;t perform very well at all.  Having moved to primarily javascript development, my first reaction is to take my face and plant it firmly in my palm.
I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>Just saw an article on ZDNet in which they benchmark the javascript performance of IE8 RC1 with other browsers.  Sadly, it looks like Microsoft&#8217;s javascript engine doesn&#8217;t perform very well at all.  Having moved to primarily javascript development, my first reaction is to take my face and plant it firmly in my palm.</p>
<p>I&#8217;m sure Microsoft will try to make up for this lack of speed with extremely aggressive caching&#8230;</p>
<div id="attachment_759" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.zdnet.com.au/news/software/soa/Internet-Explorer-8-RC1-Photos/0,130061733,339294590-4s,00.htm"><img src="http://britg.com/wordpress/wp-content/uploads/2009/01/ie8-090127-1.jpg" alt="IE8 RC1 javascript performance courtesy of ZDNet" title="ie8-090127-1" width="600" height="254" class="size-full wp-image-759" /></a><p class="wp-caption-text">IE8 RC1 javascript performance courtesy of ZDNet</p></div>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/01/27/great-another-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Results are in &#8211; No One Likes Working With Time</title>
		<link>http://britg.com/2009/01/15/results-are-in-no-one-likes-working-with-time/</link>
		<comments>http://britg.com/2009/01/15/results-are-in-no-one-likes-working-with-time/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 13:14:52 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[timeago]]></category>

		<guid isPermaLink="false">http://britg.com/?p=557</guid>
		<description><![CDATA[I recently performed a very Scientific survery asking &#8216;do you like working with time?&#8217;  I don&#8217;t mean &#8216;working with time constraints&#8217;, or &#8216;working with a person whos name is Time but they probably spell it like PThyhm (the P is silent).&#8217;  No, I mean working with time (timestamps, date formating, human-friendly time representation, etc) in [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-560" href="http://britg.com/2009/01/15/results-are-in-no-one-likes-working-with-time/20fswp3/"><img class="alignright size-medium wp-image-560" title="20fswp3" src="http://britg.com/wordpress/wp-content/uploads/2009/01/20fswp3-211x300.jpg" alt="20fswp3" width="211" height="300" /></a>I recently performed a very Scientific survery asking &#8216;do you like working with time?&#8217;  I don&#8217;t mean &#8216;working with time constraints&#8217;, or &#8216;working with a person whos name is Time but they probably spell it like PThyhm (the P is silent).&#8217;  No, I mean working with time (timestamps, date formating, human-friendly time representation, etc) in your code &#8212; do you like it?</p>
<p>The results may or may not surprise you.  With a sample size of 1, most if not all of those surveyed responded that they very strongly dislike working with timestamps!</p>
<p>I strongly agree with the person surveyed, so that&#8217;s why I&#8217;m so elated that I stumbled upon this repo on github the other day &#8212; <a title="jQuery Timeago" href="http://github.com/rmm5t/jquery-timeago/tree/master">jQuery timeago</a>.  Yes!  Finally I can just dump my timestamps straight from the database onto the page, call $.timeago(&#8217;selector&#8217;), and bam &#8212; a perfectly human readable, self updating time representation.</p>
<p>If you&#8217;re one of the many that agree with the extremely scientific survey above, then I highly recommend you give this jQuery plugin a try &#8211; here&#8217;s the plugins <a title="jQuery Timeago" href="http://timeago.yarp.com/">homepage</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2009/01/15/results-are-in-no-one-likes-working-with-time/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Who Google Chrome Affects the Most: Adobe</title>
		<link>http://britg.com/2008/09/02/who-google-chrome-affects-the-most/</link>
		<comments>http://britg.com/2008/09/02/who-google-chrome-affects-the-most/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 19:08:24 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[google chrome]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://britg.com/?p=424</guid>
		<description><![CDATA[I see a lot of coverage of the new browser out by Google &#8211; Chrome.  And rightly there should be &#8211; this is pretty exciting stuff!  Javascript running on it&#8217;s own thread per tab?  Sweet!
I&#8217;ve also seen a lot of &#8220;Should Mozilla be pissed?&#8221; or &#8220;How will this affect Microsoft?&#8221; etc.  But I haven&#8217;t seen [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://britg.com/wordpress/wp-content/uploads/2008/09/logo_sm.jpg"><img class="alignright size-full wp-image-426" title="logo_sm" src="http://britg.com/wordpress/wp-content/uploads/2008/09/logo_sm.jpg" alt="" width="150" height="55" /></a>I see a lot of coverage of the new browser out by Google &#8211; <a href="http://google.com/chrome">Chrome</a>.  And rightly there should be &#8211; this is pretty exciting stuff!  Javascript running on it&#8217;s own thread per tab?  Sweet!</p>
<p>I&#8217;ve also seen a lot of &#8220;Should Mozilla be pissed?&#8221; or &#8220;How will this affect Microsoft?&#8221; etc.  But I haven&#8217;t seen a lot of coverage on who I think is affected most by this move: Adobe.  Why?  Because the whole concept behid Chrome is to spead up web applications, namely Google&#8217;s style of web applications which all happen to be using AJAX instead of Flash.</p>
<p>So, if Google has completely revamped it&#8217;s javascript engine in Chrome so that each tab operates javascript in it&#8217;s own thread, and you can run AJAX applications like google docs, gmail, etc. continuously without worrying about your browser bringing down your entire computer, we&#8217;re likely to see a renewed interest in AJAX as a platform.  Also, we&#8217;ll see a renewed effort from other browser vendors to make their javascript engines comparible.  This is all bad news for Adobe Flex/Flash.</p>
<p><a href="http://britg.com/wordpress/wp-content/uploads/2008/09/dlpage_lg.jpg"><img class="alignleft size-medium wp-image-433" title="dlpage_lg" src="http://britg.com/wordpress/wp-content/uploads/2008/09/dlpage_lg-300x244.jpg" alt="" width="300" height="244" /></a>How are you, as a web developer, going to build that next business app?  Using Adobe&#8217;s Flex/Flash platform that requires users have a plugin installed (although most do) but has all the limitations of Adobe&#8217;s Flash plugin running in the browser?  Why would you when for most business applications, AJAX can meet all your needs AND be optimized to run as well as desktop applications?</p>
<p>No matter what the outcome, it&#8217;ll definitely be fun to see how this plays out!</p>
<p>Oh, and I&#8217;m writing this blog post through Chrome &#8211; it&#8217;s so new and shiny, <a href="http://www.google.com/chrome">go get it now</a>!</p>
<p><strong>Update: Chrome doesn&#8217;t have to gain huge market share for this scenario to play out!</strong></p>
<p>Chrome is open source and hence their Javascript Engine is open source!  (<a href="http://chromium.org/">http://chromium.org</a>) So, Chrome doesn&#8217;t have to make a huge dent in market share to make a huge dent in how the other browsers support javascript and AJAX apps.</p>
<p>From limited testing over about 2-3 hours I could noticeably tell a difference in performance running Gmail, Google Docs, Google analytics, and google reader in separate tabs as opposed to doing this on firefox.</p>
<p>This tells me that their javascript engine technology is superior to others out there &#8211; and since it is open source, I can imagine a scenario where other browsers, especially mozilla, adopt this engine.</p>
<p>So, google chrome may never ever gain market share but I&#8217;m willing to bet their javascript technology will! This is what bodes poorly for Adobe in my opinion &#8211; a new browser market that isn&#8217;t dominated by Chrome per se, but is dominated by fast and multi-threaded javascript engines!</p>
]]></content:encoded>
			<wfw:commentRss>http://britg.com/2008/09/02/who-google-chrome-affects-the-most/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
