开发者

Why do sites like twitter, gawker use #! instead of simple URL? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

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

Twitter's prof开发者_开发问答iles 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜