December 07, 2010
We lost the browser state when we replaced our Charts UI w/AJAX manipulation. While it’s possible to maintain state using an anchor ala Gmail (ie – gmail.com/mail?#inbox/THREAD), it breaks the separation between business and view logic. The server cannot access the state information contained in the anchor – it’s only accessible from the browser.
This will cause the URL bar to display http://mozilla.org/bar.html, but won’t cause the browser to load bar.html or even check that bar.html exists.
replaceState(), which modifies the current history item. It doesn’t create a new one. Why not
replaceState()meets our needs: sharing the location in the URL bar and refreshing the page should reflect the current state of the chart.
pushState()would still require business logic in our views to support the back button. While it’s easier to access the data through the
stateObjthan parsing from the anchor tag, it’s not worth the complexity in our case.
It’s a beautiful three-liner considering past alternatives:
window.history functions are supported in Firefox 4, Chrome 6, Safari 5, and Mobile Safari on iOS 4+.