Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

http

url

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?

like image 776
Jakub Troszok Avatar asked Feb 08 '11 18:02

Jakub Troszok


2 Answers

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

like image 52
ceejayoz Avatar answered Sep 24 '22 03:09

ceejayoz


'?' 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).

like image 20
Ian Clelland Avatar answered Sep 23 '22 03:09

Ian Clelland