Before we launched the site we quickly recognized how annoying it was that the browsers back button didn't work while searching and reading messages. Because the site has some Ajax goodness, we knew that getting browser history working properly would take a bit of effort so we skipped it for the launch.
However, when I saw this post on Ajaxian about the new release of Really Simple History I figured I'd play around a bit. The documentation for the library could be a bit more extensive, but because it truly is so simple to use I got things figured out in no time. Even better than being simple, its support for various browsers is fantastic.
Even though the library does a ton of the heavy lifting for you, there was thankfully some fun left for me. The library works by adding on a fragment identifier in the url (you know, that bit in the location bar after the #). Fragment identifiers are usually used to jump you to a specific part of a page. This jump doesn't cause a page refresh but fortunately it does add an item in the browsers history.
So to get things to work I had to figure out a way to encode the state of the browser into a fragment identifier. The state includes things like your current query, what page of search results you're on and what message you're reading. I ended up using a scheme similar to GET variables (key:value pairs) so that part was pretty easy.
So now I was able to add items in the browsers history, sweet! But that's only half of the story. When the user actually uses this history, it's up to us to decode the fragment identifier and properly restore the state of the browser. This turns out to be a touch tricker than it sounds. Mostly because we don't want to refresh parts of the page that don't need to be refreshed.
The site required a few other tricks to get things working, but overall the process was much easier than expected. So have some fun now that you no longer need to think so hard about that click. Thanks to Brad Neuberg and Brian Dillard for their work on Really Simple History.
Thursday, December 6, 2007
Lack of History is History
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment