Live data from Hacker News

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

news.ycombinator.com

41–50 of 71 posts

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

#41

I had always assumed they did this for financial reasons. The hash won't be sent along as part of the referrer header, so the search query won't be available to 3rd party analytics. The only way to track search queries is to use Google's own analytics, which can correlate queries to traffic since it's watching both ends of the handoff. The technical explanation discussed in this thread is certainly valid. But it only…

There are good technical explanations of the behaviour in the comments. And the observed behaviour is that only subsequent queries get put in the hash instead of the query.

The why is also addressed by the comments (IE only got support for pushState after the solution was already built).

Besides, for a long time, Google added intermediate pages when you clicked through a search result, adding the appropriate referrers right back in.

I don't think you need to attribute this behaviour to malice when a simple technical explanation suffices.

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

#42

Earlier quoted context omitted.

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

Would that not remove the possibility for sharing or manually editing the URL? (I'm asking because I don't know how much cool stuff pushState can do.)

Not unless the server doesn't interpret the URL the same way.

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

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

"never sent to the server"

It's sent in a separate request.

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

#44
post #33
post #18

Earlier quoted context omitted.

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.

the server doesn't have access to anything following the hashtag. This is only accessible on the client side via javascript. Javascript that you do not have unless the browser send the first request.

That's what I said:

> 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.

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

#45
post #18

Earlier quoted context omitted.

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.

Where do you think the initial js comes from? The "wonderland" query.

I know but the comment I was responding to said Google couldn't possibly know about the duplicate parameter. Well, here you have it, they can. Not at first, but still before displaying the results.

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

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

"never sent to the server" It's sent in a separate request.

That's because a request is manually created with javascript; this is not because it's part of the url. If you append #something to most random url's, nothing will happen (unless specific behaviour was written to do so).

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

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

I'm on Chrome, and even if I search directly from google.com (google.co.uk) I see my search query as a proper query variable.

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

#48

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…

Why would google.com/?q=search-term not be bookmarkable?

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

#49
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

Yes, and if you're using Firefox, you can this with the knowledge of its Smart Keywords to create super quick shortcuts! https://support.mozilla.org/en-US/kb/how-search-from-address... For example, I directly go to Wikipedia's page on "India " by typing wp India in my address bar using these search keywords, or search images of birds on google by typing gi birds in it. (There's a rather cumbersome way to do the same…

I've had one of these for YouTube for years, really excellent feature.

Opening a new tab with yt is such a habit now.

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

#50
post #49

Earlier quoted context omitted.

Yes, and if you're using Firefox, you can this with the knowledge of its Smart Keywords to create super quick shortcuts! https://support.mozilla.org/en-US/kb/how-search-from-address... For example, I directly go to Wikipedia's page on "India " by typing wp India in my address bar using these search keywords, or search images of birds on google by typing gi birds in it. (There's a rather cumbersome way to do the same…

I've had one of these for YouTube for years, really excellent feature. Opening a new tab with yt is such a habit now.

Exactly the same for me!
Post reply on HN