Hashbangs, useful, but probably not what you want

In the modern web AJAX is the workhorse behind the interactions. CSS3 might add the shine but AJAX is still doing the work. The strength of AJAX is that it’s a background request, the UI will ignore them completely, which is fantastic unless you’ve just ripped out the hole page content and replaced it with another one.

To enable the user to track that changed state you need to change the URL, and this is where hashbangs come in. Hashbangs are a work-around. But Hashbangs are an old workaround for an old problem.

Where previously we only has window.location available to us we now have the history API, window.history.

Use pushState to add states and watch for the popstate event to revert to previous states.

One final caveat, if you are updating only a region of your page then a hashbang may still be valid for you. The hashbang URL must convert into a querystring URL for search engines to parse the content. They expect only the changed content to be returned when they visit that converted URL.

Resources

Filed under: JavaScript