Search code examples
javascriptapigithubbrowser-historyhtml5-history

Hashtags (Fragment identifiers) VS Javascript History API


Which one is better? Using fragment identifiers...

http://www.alinkthatdoesnotwork.com/#!/dir1/dir2/file.html

...or the new Javascript History API?

https://github.com/examplethatdoesnotwork/project/src/script.js

Or should I use both? (via fallback)

Aspects:

  • Compatibility/Support
  • Speed
  • Convenience

Solution

  • Hashtags are a means to categorise content on Twitter, you mean fragment identifiers.

    Using fragment identifiers to indicate what content to load via Ajax is a terrible idea. They are a hack that is fragile, search engine unfriendly (except with more hacks on both sides) and depends on JavaScript.

    The history API is a robust system that is actually designed to do that job. The only problem with it is browser support, but (unlike the fragment identifier approach) it gracefully degrades to real URIs that will be passed directly to your server (which is what Github does).

    Even Twitter appear to be about to switch to the history API.