AJAX and the Browser Back Button AJAX and the Browser Back Button ajax ajax

AJAX and the Browser Back Button


Use ajax for portions of the page that needs to update, not the entire thing. For that you should use templates.

When you want to still preserve the back button for your various state changes on the page, combine them with # achors to alter the url (without forcing the browser to issue another GET).

For example, gmail's looks like this:

mail.google.com/#inbox/message-1234

everything past the # was a page state change that happened via ajax. If I press Back, I'll go to the inbox again (again, without another browser GET)


If you're going to enable AJAX, don't do it at the expense of having accessible URLs to every significant page on your site. This is the backbone of a navigable site that people can use.

When you shovel all your functionality into AJAX calls and callbacks, you're basically forcing your users into a single path to access the features and content that they want -- which is totally against how the web is meant to function. People rely on the address bar and the back button. If you override all your links so that your site is essentially a single page that only updates through AJAX, you're limiting your users' ability to navigate your site and find what they need. It also stops your users from being able to share what they find (which, that's part of the point, right?).

Think about a user's mental map of your site. If they know they came in through the home page, then they went to search for something, then they landed on a games page, then they started playing a particular game, that's four distinct units of action that the user took. They might have done a few other smaller, more insignificant actions on each of these pages -- but these are the main units. When they click the Back button, they should expect to go back through the path they came in on. If you are loading all these pages through AJAX calls, you're providing a site whose functionality runs contrary to what the user expects.

Break your site out into every significant function (ie, search, home, profiles, games -- it'll be dictated by what your site is all about). Anywhere you link to these pages, do it through a regular link and a static URL.

AJAX is fine. But the art of it is knowing when to use it and when not to. If you keep to the model I've sketched out above, your users will appreciate it.


Check out reallysimplehistory. The wiki hasn't been updated for 10 months, but I was just at the Ajax Experience 2008 and saw a presentation by Brian Dillard on it. He says the 0.8 code is on his hard drive. Hopefully, it will be downloadable soon.