News for hackers. Stuff that matters.
Re:Ask HN: Why does Google put the query in the URL hash ins... by kc10 on Monday January 09, 2017 @01:58AM (#13354564)
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 ins... by michaelvillar on Monday January 09, 2017 @03:07AM (#13354788)
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 ins... by wmil on Monday January 09, 2017 @03:31AM (#13354875)
They could if they were building it now. IE got pushState support in IE 10 in 2012.

The hash state has been there since Instant Search was launched in 2010.

Re:Ask HN: Why does Google put the query in the URL hash ins... by lloeki on Monday January 09, 2017 @08:39AM (#13356196)
Graceful degradation/progressive enhancement is a thing, though.
Re:Ask HN: Why does Google put the query in the URL hash ins... by bpicolo on Monday January 09, 2017 @08:56AM (#13356288)
The amount of money Google makes supporting older browsers is most likely measured in billions.

Not to mention, why fix something that isn't broken? There are cases for it, but it's roughly the same tech that it was 4 years ago. What would they gain by spending developer time on it?

Re:Ask HN: Why does Google put the query in the URL hash ins... by iurisilvio on Monday January 09, 2017 @12:13PM (#13357852)
Perfect. They definitely don't need optimization for search engines, which is probably the most important reason to a clean URL.
Re:Ask HN: Why does Google put the query in the URL hash ins... by adamdonahue on Monday January 09, 2017 @09:39AM (#13356578)
Exactly. You are someone who gets it.
Re:Ask HN: Why does Google put the query in the URL hash ins... by heisenbit on Monday January 09, 2017 @02:14PM (#13358904)
I suspect they spend a ton of developer time. It is their #1 source of income. What they won't do is releasing it unless it is 99.9% certain that it yields an improvement.
Re:Ask HN: Why does Google put the query in the URL hash ins... by untog on Monday January 09, 2017 @09:22AM (#13356440)
Yes, but in this case the benefits of the enhancement are small enough that Google may have decided that consistent behaviour was more desirable.
Re:Ask HN: Why does Google put the query in the URL hash ins... by paulddraper on Tuesday January 10, 2017 @02:45AM (#13363363)
Consistent and long-lasting support is a thing too.

Rare on today's web, but still a thing.

Re:Ask HN: Why does Google put the query in the URL hash ins... by thomasahle on Monday January 09, 2017 @05:52AM (#13355415)
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 ins... by dpark on Monday January 09, 2017 @09:58AM (#13356724)
No, but it makes shared links less inefficient. If you share a URL like this, the server will not receive the hash on the initial request, so the js client will have to do the search as a second request after the page load. The reality is that most users will never even notice because it's still fast.

Manually editing the link causes that same fetch-render-refetch flow.

Edit: Oh, you were asking about pushstate. No, that specifically fixes the problem with the double fetch, so long as the server side and client side do the right thing to make the user see the same page for the same URL.

Pushstate just lets the JS client modify the URL without triggering a page reload, so the client can change the actual query param instead of the hash.

Re:Ask HN: Why does Google put the query in the URL hash ins... by TazeTSchnitzel on Monday January 09, 2017 @06:05AM (#13355475)
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 ins... by draw_down on Monday January 09, 2017 @10:46AM (#13357125)
The fragment of a URL is not sent to the server as part of an HTTP request
Re:Ask HN: Why does Google put the query in the URL hash ins... by dx034 on Monday January 09, 2017 @02:45AM (#13354713)
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 ins... by Sacho on Monday January 09, 2017 @02:54AM (#13354745)
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 ins... by lucb1e on Monday January 09, 2017 @03:11AM (#13354802)
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 ins... by comboy on Monday January 09, 2017 @05:32AM (#13355343)
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 ins... by baby on Monday January 09, 2017 @04:56AM (#13355222)
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 ins... by lucb1e on Monday January 09, 2017 @07:11AM (#13355747)
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 ins... by qeternity on Monday January 09, 2017 @05:00AM (#13355237)
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 ins... by lucb1e on Monday January 09, 2017 @07:12AM (#13355753)
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 ins... by onion2k on Monday January 09, 2017 @03:13AM (#13354811)
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 ins... by diamondo25 on Monday January 09, 2017 @03:44AM (#13354922)
Don't forget that the hash part is client sided; Google doesn't know about it until the page is loaded.
Re:Ask HN: Why does Google put the query in the URL hash ins... by wodenokoto on Monday January 09, 2017 @05:35AM (#13355356)
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 ins... by oneeyedpigeon on Monday January 09, 2017 @07:36AM (#13355876)
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.