4

Possible Duplicate:
What's the shebang (#!) in Facebook and new Twitter URLs for?

Twitter's profiles now have URL in the form of:

http://twitter.com/#!/username

instead of the simpler structure:

http://twitter.com/username

What does #! do? What is the advantage of using #!? I read that it's related to google's web crawler, but I don't understand how exactly does that work.

Community
  • 1
  • 1
Continuation
  • 12,722
  • 20
  • 82
  • 106
  • Stupidity would be my answer - http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs – Phil Feb 09 '11 at 23:56
  • +1 for an article that gives an excellent explanation. -1 for saying that it's stupid, when it improves page loading speed. – Michael Aaron Safyan Feb 10 '11 at 00:00
  • Driving at 130mph would improve the time it takes to get somewhere. That doesn't stop it being stupid. – Quentin Feb 10 '11 at 00:02
  • Thank Rob Allen (@akrabat) for bringing it to my attention – Phil Feb 10 '11 at 00:04
  • Page speed is fairly important. Rather than sacrifice site speed, there are better ways to provide site stability such as automated JavaScript tests, strict regression testing and monitoring, having a little bit of JavaScript that never changes and which causes the links and the page to revert to the old behavior if external JavaScript cannot be reached, etc. – Michael Aaron Safyan Feb 10 '11 at 00:06
  • @Michael Well, it was a pretty silly move on Gawker's part. I also agree with that article completely, especially regarding *"Lifehacker/Gawker have thrown away a decade’s worth of clean URL experience, and ended up with something that actually looks worse than the typical templated Classic ASP site."* – Phil Feb 10 '11 at 00:13

2 Answers2

7

There are two parts to this:

Why a fragment identifier instead of a real page?

Because they are overusing Ajax. Instead of linking to a new page, they link to a non-existent or dynamically generated fragment of the current page and then use JavaScript to change the content.

Why start the fragment identifier with !

Because Google will map it onto a different URL so you can serve up a special alternative version just for them. This allows the content to be indexed by search engines.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • It isn't overusing Ajax. To users, it would appear that the page loads faster, since the layout will render immediately (assuming it's still cached). – Michael Aaron Safyan Feb 09 '11 at 23:59
  • 2
    Caching has nothing to do with it - the data is still on the page. If the page was reloaded then the (easy to compress) markup would be sent again, and the images, css, js, etc would be loaded from cache. It is overusing Ajax (note that this *is* subjective). There is a benefit, but there are also costs (note that this is *not* subjective). – Quentin Feb 10 '11 at 00:07
2

In a URL, the contents after the hash mark (#) are not sent to the server, but is instead visible to JavaScript on the page. So, using a # basically allows the page "http://twitter.com/" to handle it (for example, by opening up background connections to load up additional data). This also means that the content that doesn't change from one page to another (think the general layout of the page) can be cached and served immediately (since the effective URL is still "http://twitter.com/"), whereas putting it in the path of the URL (without the hash) would require a full separate fetch to get that layout.

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200