Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If Google's homepage is so minimal, why is the source hundreds of lines of code? [closed]

The code is minified, but reformatted is a few hundred lines of code. I'd imagine such a minimal page to have minimal code as well. What is it that Google is doing that the source is this long? I can see a lot of it is javascript, but I was under the impression that inlining so much javascript was bad practice.

like image 279
chrislgarry Avatar asked Apr 05 '14 06:04

chrislgarry


People also ask

How many lines should an HTML file be?

Avoid lines longer than 80 characters. When a statement will not fit on a single line, it may be necessary to break it.

How do you view the source code of a website?

To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select View source from the pop-up menu that appears.


2 Answers

At least one chunk of that code is used for the ajax callbacks for Instant Search.

Also, when you consider whether inlining Javascript is bad, you should think about the alternative. If the code was in a separate file, it would be another http request, which means that the page would load with higher latency.

like image 90
merlin2011 Avatar answered Sep 27 '22 22:09

merlin2011


The JavaScript is probably not inlined in their unbuilt source. That would be potential bad practice. By inlining it into the page source when built, the page won't have to make any additional HTTP requests to download a separate resource file, as HTTP requests are one of the slowest parts of loading a web page.

The sheer amount of JS is, by my guess, probably due to a lot of common libraries and code shared among many of their pages, and trying to have it not load on their homepage would end up involving a lot of unnecessary and nasty workarounds in their code. Plus, the UI may look simple, but how much is actually happening under the hood? There are Google accounts to worry about, instant and voice searching to do, analytics tracking, etc.

In the end, however, you probably won't truly know unless you get a Google engineer to divulge their secrets, or get a job with them.

like image 32
ajp15243 Avatar answered Sep 27 '22 22:09

ajp15243