开发者

'?' versus '#!' in URLs [duplicate]

开发者_Go百科This question already has answers here: Closed 12 years ago.

Possible Duplicate:

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

Why there are more and more websites (for example twitter or gawker) using '#!' instead of '?' to separate parameters from the rest of URL? What are the advantages?


It is becoming a standard way, proposed by Google, of making AJAX web applications crawlable.


'?' is used to separate the path component of the URL from the query component. When a browser requests such a resource, both components are sent to the web server. The server can look at the query and determine what response to send back.

'#' is used differently -- it separates the 'fragment' or 'hash' component from the rest of the url. The fragment component is never sent to the web server, but it is available to any scripts running in the page.

Comparing two URLs, say

http://www.example.com/service/?my+query

and

http://www.example.com/service/#!my+query

In the first case, the whole url is sent to the server, and a response is returned. Any caches along the way, from the browser all the way to the server, will see the query string, and know that the response is only relevant to that query. They may cache the response for that query, but more likely will not cache the response at all.

With this scheme, this means that if example.com is a popular service, they will have to send a full response to every single user of the service, and it is very likely that none of their results will be cached anywhere.

In the second case, only the path component, http://www.example.com/service/ is used, and the server will (likely) return the same document to every user requesting that URL. Upstream caches will be able to cache that document, and serve it to new users without going back to the origin web server for every request.

With this scheme, there will probably be some JavaScript running on that document which looks at the fragment, and then requests any additional search results from the service. These could be much smaller than an entire page, reducing the load on the server, or they could be cacheable results, available to multiple users.

The specific form, '#!', is an emerging standard for AJAX-style web applications, so that their URLs can be indexed by search engines, or analyzed by web-analytics software. The actual URL spec only mandates the '#' character, and it can be used for other purposes as well (like named anchors within a document).


Using the pound sign is handy when you are building an ajax-heavy site. Sites that show new content without reloading the page typically still update the url so specific content can be linked to. You can only change the portion of the url after the '#' without reloading the page (to prevent sites from pretending they live at a different domain than they do).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜