Live data from Hacker News

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

news.ycombinator.com

31–40 of 71 posts

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

#31
post #7

Earlier quoted context omitted.

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

Is there any technical reason for this? Because as far as I know the keywords still appear in Webmaster Tools.

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

#32

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…

It's not that cumbersome in Chrome. Right click the URL bar -> "Edit search engines" -> Find the search engine you'd like to easily search, double click the second column and enter a keyword for it. For example, for wikipedia, I have "wp" as a keyword. In the URL bar, you can just type "wp " and you can search wikipedia.

you don't even have to do any configuration. after you've used a search box that's correctly formatted (like wikipedia's is) chrome automatically offers you the option to "press tab to search" when you start typing that's site's url.

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

#33
post #18
post #15

Earlier quoted context omitted.

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.

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.

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

#34
post #18
post #15

Earlier quoted context omitted.

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.

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

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

#35
post #18
post #15

Earlier quoted context omitted.

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.

Why all the downvotes? I think he means that it could prevent the alice query, not the wonderland.

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

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

For what it is worth, Safari on OSX goes straight to "alice" results, but I think Safari handles google.com differently than other domains.

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

#37
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 explains what is happening. The question posed was "why". Why would a search engine implement a design that would have the effect of removing the query string from referrer headers?

Answer that, and you'll answer your question

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

#38
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?

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

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

#40
post #30

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…

Set DuckDuckGo as your default search engine and you don't even need to do any configuring. You can then just type `!wiki India` or `!gi birds` or any other !bang: https://duckduckgo.com/bang

I've tried that, and while it is nice and useable it is also significantly slower, going through DDG for one more complete roundtrip, than it is going directly to a URL you already know.
Post reply on HN