Bookmarking AJAX applications in Iliad and fixing the back button

Tagged:  •  

There is a new feature in recent versions of Iliad which allows you to bookmark your AJAX applications and use the back button, using the hash (fragment) of the url.

The idea is to associate a hash to an action. When the action will be evaluated, the corresponding hash will be added to the url by the javascript layer.

To retreive the application state from the hash, a new dedicated route named hashRoute has been introduced.
This route can be used and streamed forward like any other route.

To learn more about routes in Iliad, you can read this post.

For example, in a view of a blog application, if we want to be able to select a given post by clicking on its title, but doing it the AJAX way and still being able to bookmark it, we could write something like this:

e anchor
    h1: aPost title;
    action: [self selectPost: aPost] hash: 'post/', aPost path.

When the action is evaluated, the url is updated to:


The next step is to be able retreive the application's state from the url, for initial requests, when you give a link to someone or refresh the page for example. To do this, we will stream the route:

self hashRoute next = 'post' ifTrue: [
    path := self route next.
    selectedPost := self posts 
        detect: [:each | each path = path]
        ifNone: [nil].

This way, bookmarking AJAX applications becomes easy, and you still think of
the control flow in term of actions. Also, it will add entries to the history, so the back button will still work.

Best of all, it will continue to work without javascript enabled, as always with Iliad, by making normal requests and just not using the hash.

Now works on IE6/7 too!

User login