Live data from Hacker News

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

news.ycombinator.com

11–20 of 71 posts

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

#11
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]

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

#12
post #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.

No. Keywords do not appear in Google Analytics since search switched to HTTPS. The query strings are dropped going from HTTPS to HTTP. Keywords will show up as "(not provided)"(Disclaimer: I work at Google but I'm not on the search team. I do use Google Analytics.)

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

#13
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…

Interesting that your alice/wonderland example works. Would've thought Google would try to prevent that.

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

#14
post #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!

And if you set num=0 then it returns the normal "did not match any documents" page: https://www.google.com/search?num=0&q=temperature+london

Which seems like it could be used to fool someone into thinking there really are no results for a subject.

Or to pretend Google search is broken ;)

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

#15
post #13
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…

Interesting that your alice/wonderland example works. Would've thought Google would try to prevent that.

I don't think they can - iirc the hash isn't sent to the server, so to it this looks like any other normal query.

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

#16
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…

They could use `pushState` to change the query without reloading the page?

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

#17
Anchors are not part of a referer sent to external websites; also, it will not be logged in webserver logging since it's never sent to the server. Everything from # on is stripped off and stays on the client. The only way to interact with it, is via javascript.

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

#18
post #15
post #13

Earlier quoted context omitted.

Interesting that your alice/wonderland example works. Would've thought Google would try to prevent that.

I don't think they can - iirc the hash isn't sent to the server, so to it this looks like any other normal query.

Well sure they can, how do you think the search results for "alice" are obtained? It gets sent to the server, just not upon first load but using Javascript. This Javascript could check for another query being present in the query string, or (less reliably) the server could in the referrer.

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

#19
post #13
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…

Interesting that your alice/wonderland example works. Would've thought Google would try to prevent that.

As far as Google are concerned it makes no difference if the query is a GET variable in the URL or a hash fragment that their JS code sends as a query after the search page is loaded. They both mean "load Google Search with this parameter from the URL".

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

#20
As others have said, it's to show the data without reloading the page.

They could of course do it without actually adding anything to the url - but then it won't be bookmarkable (and refresh would get you back to a page without results).

They could use the new history pushstate api, but then: 1. it won't work in older browsers 2. if they wanted it to work in older browsers they'll have to shim it (which ends up using hashes anyway) - and maintain it, and it will add the the page download size, which google (at least in the main site) take very seriously.

Post reply on HN