HTML5 — Barcamp Auckland 5

Friday, 22 July 2011

The last proper session I went to at Barcamp Auckland 5 was “Extreme AJAX – beyond the hashbang, building a robust single page JS framework and URL schema”, presented by Barry Hannah (@barryhannah) & Mark Zeman (@markzeman). They worked on the excellent newzealand.com redesign and gave some insight into its engineering.

At a high level, the most interesting part of the design is the navigation: no hierarchy, just tags. Opinions were divided, but I like the purity and elegance of the idea, and the implementation gives a lot of structure to the tags.

At a low level, they described the initial URL scheme they came up with. The site is implemented as a single-page site, with all content updates done with Ajax. For modern browsers, they use the history API to seamlessly change the URLs. For example, if a user clicks a “Travel” link, the browser address bar will switch from http://nz.com/ to http://nz.com/travel without refreshing the whole page. (Opera offer a good history API introduction.)

Browsers that don’t support the history API instead use Google’s Hash fragments specification: browsers would see the URL http://nz.com/#!travel, while web crawlers would see http://nz.com/?_escaped_fragment_=travel . (See the spec for the reasoning behind this.)

Eventually they realised they didn’t need to use hashbangs at all. HTML5 browsers, with their fancy history API, end up being able to use plain URLs like http://nz.com/travel without ever refreshing the whole page. But crawlers can use the same URLs to fetch whole pages — the backend can easily tell whether a request is coming from a crawler or a browser. And less capable browsers can just use a plain hashy URL like http://nz.com/#travel.

This is quite a nice solution, except that if a web crawler does get hold of an URL like http://nz.com/#travel, it will only ever see the site homepage. That’s an SEO fail. But they point out that this probably won’t have much of an impact because the proportion of such links floating around won’t be high.

They talked about various libraries they used to do this: jQuery plugins Pjax and History.js and the JavaScript MVC framework Backbone. (Poking around the Pjax page I discovered a very useful online Closure compiler service that actually hosts compiled code!)

I really enjoyed seeing this lively presentation from a team who are pushing a large public website into the HTML5 world. I’m feeling inspired for my next project!

Tags: , , , ,

Leave a comment