views:

134

answers:

2

How Do Google and Bing's Autocompletion Work?

When I use firebug I see no XHR's. In that case, how is the data retrieved?

+3  A: 

They create <script> elements that point to URLs that return Javascript that calls a function with the results of the autocomplete. (Similar to JSONP)

You can see the requests in Firebug's Net tab.

SLaks
+3  A: 

XHR is restricted to the same domain as the source request, whereas Google and Bing use separate domains to serve their dynamic content.

Instead, they dynamically load new data by adding <script> tags to the page (which show up in the "All" tab of Firebug)

Gareth
Thanks. Do you know why they use separate domains?
Matt H
@Matt H, I'm not sure, but probably when you serve that much searches per second as google or bing does, you need more than one server, and they are seperated with different domains. That's my guess!
Tom
I'm not going to second-guess Google and Bing's infrastructure needs ;)
Gareth