Javascript – Using Hash Bang URL’s. Best practices? Best libraries? Important pitfalls

javascriptweb-development

SO I'm about to put together a new site and I'd like to go about it by making a web application that parses /#!/ url's and requests content accordingly via AJAX calls to a JSON API that is already put together.

My questions are…

  1. What are the best practices concerning #! url's
  2. Are there any good JavaScript libraries that are built to handle Routing as well as History? or should I roll my own?
  3. What are the pitfalls I should be aware of?

Please no "/#!/ url's are breaking the internet!" comments , I've read Mike Davies Article as well as this one and this other one.

I want to hear from people who have already implemented this type of a url structure and can tell me about their experiences.

Best Answer

Although I think pushState based routing is, in most cases a preferable solution, I understand that sometimes hash based routing is a better fit.

As others have suggested you can use davis.js, which supports pushState based routing by default, but can work just as well with hash based routing if you need it, see the code here.

Related Topic