Live data from Hacker News

Ask HN: Why does Google put the query in the URL hash instead of query string?

news.ycombinator.com

1–10 of 71 posts

Ask HN: Why does Google put the query in the URL hash instead of query string?

#1
Search for something on Google, and the URL will look something like this:

https://www.google.com/?gfe_rd=cr&ei=some_long_string&gws_rd=ssl#q=something

The search query is the `#q=something` part of the URL, whereas other parameters are stored in the URL via the query string (the part between `?` and `#`). Why is that? Why isn’t the search query stored in the query string? Why in the hash?

Re: Ask HN: Why does Google put the query in the URL hash instead of query string?

#3

Because subsequent searches aren't full page reloads. The first search (via the Chrome URL bar) puts the search in the "q" query string for me.

> Because subsequent searches aren't full page reloads.

This does not mean google cannot rewrite the url without reloading the page (via history.pushState). But less browsers supports this [1] (IE9, browsers from 2009, and some android browsers).

[1]: http://caniuse.com/#search=history.pushState

Re: Ask HN: Why does Google put the query in the URL hash instead of query string?

#4
On a related note, and probably obvious to many, I've just discovered I can make a nice little link to a one-result search, handy for a bookmark.

Things like current temperature and forecast I don't want a dedicated app for when a simple search is more efficient...

https://www.google.com/search?num=1&q=temperature+london

Re: Ask HN: Why does Google put the query in the URL hash instead of query string?

#6
If you are search from any place (toolbar, addressbar) other than google.com, your search query would be passed in as a query string.

But once you are already on google.com search page, the entire page need not be reloaded. So google would fetch the search results for the new search string via a XHR and update the page.

In fact if you search for https://www.google.com/search?q=wonderland#q=alice, the webpage would first load the search results for 'wonderland' and once the page is loaded, there would be another XHR for 'alice' and the DOM would be updated again with the new results.

Re: Ask HN: Why does Google put the query in the URL hash instead of query string?

#7

Could it be to hide the query in the referrer? Although I think all clicks go through Google servers first.

Correct. The only service which can provide you with google queries is google analytics.

So if you want the data, you are forced to help spread the google drag net across the internet.

Re: Ask HN: Why does Google put the query in the URL hash instead of query string?

#8
post #4

On a related note, and probably obvious to many, I've just discovered I can make a nice little link to a one-result search, handy for a bookmark. Things like current temperature and forecast I don't want a dedicated app for when a simple search is more efficient... https://www.google.com/search?num=1&q=temperature+london

That's pretty neat. Didn't know that. Thanks!

Re: Ask HN: Why does Google put the query in the URL hash instead of query string?

#10
post #6

If you are search from any place (toolbar, addressbar) other than google.com, your search query would be passed in as a query string. But once you are already on google.com search page, the entire page need not be reloaded. So google would fetch the search results for the new search string via a XHR and update the page. In fact if you search for https://www.google.com/search?q=wonderland#q=alice , the webpage would f…

[deleted]
Post reply on HN