16 ms·
Ask HN: Why does Google put the query in the URL hash instead of query string?
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?
- eschutte2 10y agoBecause 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.
- k_ 10y ago> 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 http://caniuse.com/#search=history.pushState
- exodust 10y agoOn 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 https://www.google.com/search?num=1&q=temperature+london
- notriddle 10y agohttps://www.google.com/search?num=0&q=temperature+london https://www.google.com/search?num=0&q=temperature+london it's pretty funny
- ww520 10y agoThat's pretty neat. Didn't know that. Thanks!
- chrisb 10y agoAnd 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 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 ;)
- roberthensing 10y agoOr tell the truth about the truth ;) https://www.google.nl/search?num=0&q=the%20truth https://www.google.nl/search?num=0&q=the%20truth
- deleted 10y ago[deleted]
- _andromeda_ 10y agoSo cool.
- piyush_soni 10y agoYes, 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-bar 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 in Chrome as well)
- notzorbo3 10y agoIt'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<tab>" and you can search wikipedia.
- notatoad 10y agoyou 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.
- Ajedi32 10y agoYep, I use this feature all the time and I think there's only ever been one or two sites I've had to set it up for manually. For most sites, Ctrl+T <First 2-3 Letters of Site Name> <Tab> <Search Query> <Enter> works just fine without me having to configure anything.
- MiddleEndian 10y agoThe level of customization offered in Firefox is a nice benefit though, as you can add a wildcard to any portion of a URL. I have some specific shortcuts like wdir (walking directions from my home address) and some shortcuts that allow me to quickly jump to subsections of specific sites.
- Dragonai 10y agoVery cool, thanks!
- kevin2r 10y agoYou still get the google "applet" + 1 search result, any ways to get only the "applet"?
- martin-adams 10y agoCould it be to hide the query in the referrer? Although I think all clicks go through Google servers first.
- josteink 10y agoCorrect. 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.
- iamchrisle 10y agoNo. 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.)
- spullara 10y agoThey drop them from https to https using this method as well. In this case, what is good for the user is amazing for Google. They are the only ones that get access to the query stream.
- Gurrewe 10y agoIs there any technical reason for this? Because as far as I know the keywords still appear in Webmaster Tools.
- blowski 10y agoAren't all Google search pages now in HTTPS? I'd they are, then they drop the query in the referrer.
- kc10 10y agoIf 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 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.
- dx034 10y agoInteresting that your alice/wonderland example works. Would've thought Google would try to prevent that.
- Sacho 10y agoI don't think they can - iirc the hash isn't sent to the server, so to it this looks like any other normal query.
- lucb1e 10y agoWell 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.
- NKCSS 10y agoAnchors 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.
- danellis 10y ago"never sent to the server" It's sent in a separate request.
- Illniyar 10y agoAs 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.
- oneeyedpigeon 10y agoWhy would google.com/?q=search-term not be bookmarkable?
- benbayard 10y agoOP is saying if you do not update the URL between searches it will not be bookmarkable. Not, if you update the URL with the actual search term in a query string. The reason they do not update the URL query string itself is due to browser incompatibility. Doing it this way they get support for all browsers released after 2010, whereas they could only support IE 10 or greater by using History.pushState
- deleted 10y ago[deleted]
- jasonkester 10y agoI 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
- shezi 10y agoThere 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.
- jessaustin 10y agoIf that's "malice" then everything Google does is malicious. There's nothing wrong with doing something for multiple reasons. It seems exceedingly unlikely that "now we can control Referer" never came in search product discussions.
- currysausage 10y agoIf you click a search result, you still have a google.com/url?… redirector in between, so hiding the search term in the hash wouldn't really be necessary.
- karol 10y agoPretty sure they do it for search privacy as hash is not usually passed in "referer" header, so the pages visited from google search will not have access to the typed query.
- liveoneggs 10y agoI think they did it to reduce stability and occasionally render blank results pages.
- aaronmdjones 10y agoI've lost count of the amount of times I've had to force-refresh the page and enter my query all over again because of this.