Ajax URLs and breaking the back button

5 points by nopal ↗ HN
What's up with named-anchor URLs breaking the back button?

I was reading a different thread (http://news.ycombinator.com/item?id=2161405), and when I followed it, I was taken through a series of redirects: https://github.com/documentcloud/backbone/issues#issue/201 -> https://github.com/documentcloud/backbone/issues/201/find -> https://github.com/documentcloud/backbone/issues/issue/201

The redirect form the URL with the named anchor redirects to the find URL via JavaScript's window.location property, and the find URL redirects to the final URL via a HTTP Location header.

When I reach the final page and click my back button, I'm taken to the named-anchor URL, which initiates the series of redirects, taking me back to the final page.

I know the named-anchor URLs are used so that Ajax interactions are reflected in the address bar, but it's annoying when they break expected behavior when used to link directly to a page. (In fairness, this doesn't appear to be a problem in Chrome; I'm using FF)

Twitter's also been bad about this recently. (Their URLs look like they're tailored for Google, to me: http://code.google.com/web/ajaxcrawling)

Companies should make sure their code doesn't end up trapping users in a redirect loop.

In GitHub's case, I believe using location.replace instead of window.location for the first redirect would solve the problem, although I'm not sure because I haven't tried it.

Is it possible to have these types of redirects without breaking the back button? If so, why are large sites making this mistake?

4 comments

[ 4.3 ms ] story [ 16.6 ms ] thread
yes, its possible. there are lots of sites that do make use of it well/correctly.

the reason why its difficult is because it turns the app into a ajax state machine. navigation is much more programmatic, which makes the possibility of something screwing up much higher. especially in a larger, more complex system.

Not if you use HTML5's new state management. But I thought GitHub did. I've never had problems with AJAX history navigation but I know that Firefox users complain about it all the time due to how WebKit handles javascript instant redirectts.
its relatively new. not all sites that do this are going to have made that jump. github might. other sites that have problems definitely don't.

its also still totally possible to screw up html5's state management.

I think it's a different issue, but Google Analytics is terrible about breaking the back button. It drives me crazy every day.