6 ms·
A first round google interview question I was asked: If you have a web page with two images on it, how many web request will need to be made to render the page
by IanDrake 10y ago
A first round google interview question I was asked: If you have a web page with two images on it, how many web request will need to be made to render the page? (Assume http 1.1)
I had to ask if he wanted the technically correct answer or the one I bet he (the google recruiter) was given by his engineers. Sadly his google engineers had given him the wrong answer.
- jnotarstefano 10y agoI'll bite. Why is "3" the wrong answer?
- tremon 10y agoBecause a complete rendering of the page includes fetching /favicon.ico.
- chaz6 10y agoOn the other hand you only need 2 if you use css image sprites.
- tedmiston 10y agoIf there even is a favicon... and if a .ico file is considered an "image".
- shakna 10y agoIf there is no favicon... There'll still be a request, it'll just 404. Every modern browser I know of automatically tries to fetch favicon.ico.
- tedmiston 10y agoGood point. I suppose it's presumably async with respect to the render anyway. It looks even more nuanced on pages that have an iframe [1] (though presumably that's not the case here). [1]: http://stackoverflow.com/a/13416784/149428 http://stackoverflow.com/a/13416784/149428
- PanMan 10y agoSo, which were yours and their answers? I'd say usually 3, but you could do 1.
- K0nserv 10y agoSo 1 would be referring to the underlying connection which would be kept alive? Or is the interpretation that the page has "rendered" even before the images has loaded
- mapleoin 10y agoYou can do one request if you embed the picture into the html document: https://en.wikipedia.org/wiki/Data_URI_scheme https://en.wikipedia.org/wiki/Data_URI_scheme Don't really understand why either 1 or 3 would be incorrect answers. But then again... I don't work at Google.
- eknkc 10y agoI don't understand how these interviews work. You can't have a single correct answer to these kind of questions. - 3 seems to be the obvious answer. - 1 for keep alive stuff but even with a single connection, there are multiple requests. Also, nobody said the images were on the same server. - Did I have these images on cache? Maybe 1 then. - 4 with favicon request (now we are nitpicking) - Hey maybe each resource is behind 5 http redirects.. So 15 would be correct I guess? - Base64 encoded images are fun too. They really have a "set in stone correct answer" and do not discuss these with people?
- namaemuta 10y agoMaybe they are evaluating how do you answer instead of what do you answer. If your answer includes a total underestimation of the recruiter's knowledge, maybe that's an attitude that google is not looking for.
- jpalomaki 10y agoA previous discussion on HN indicated that at least on some levels they are just checking if the answers match those one that have been provided by somebody: https://news.ycombinator.com/item?id=12701272 https://news.ycombinator.com/item?id=12701272
- onion2k 10y agoIf the question states "to render the page" then it's very likely the answer is about blocking versus non-blocking calls. Images don't block the browser's renderer because they're loaded asynchronously, so the answer is 1. As soon as the browser has fetched the HTML and parsed the header for blocking scripts and CSS it'll build the DOM and render it. The images will be requested during that time, but they won't stop the rendering from happening. The browser will rerender the page as soon as the images load (or sooner if they're progressive JPEGs). The same is true of favicon.ico. That's loaded in the background after the first render. (I think that's all still true. Browsers move fast.)
- orclev 10y ago
- adtac 10y agoAm I allowed to Base64 encode the image into the HTML document?
- bfrog 10y agoWouldn't this entirely depend on the web browser behavior? If I'm using lynx, its 1... 1 request.