It is best to have JavaScript after the content, so JavaScript does not block the page loading.
See Steve Sounder's blog entry for more details.
Part of window.jQuery || loads jQuery from a locally hosted copy if a CDN copy is not available.
Basically, the script tag downloads jQuery from Google servers, which are really fast and located around the world. Plus, since many sites download jQuery from Google servers, which many people cache in their browsers. In any case, people will get it very quickly.
The problem is that if the Google servers are down, the jQuery download will fail. To protect us from this unlikely lineup after loading jQuery from Google, we have a JavaScript expression. This is a conditional expression A OR B In this case, the left side of the expression is a jQuery variable, if it was successfully downloaded from Google, it will be a global jQuery object, which is a "true" value in JavaScript, it will be evaluated as true. Since the OR expression, if one side is true, there is no need to evaluate the B-side, JavaScript will never execute the rest of this line of code. This is called a short circuit rating .
If jQuery could not be downloaded from the Google CDN, the jQuery global variable will be undefined. This value is false, so JavaScript will execute the correct side of the OR expression. The right side in this case writes a new script tag on the page. The new script tag loads jQuery from the relative domain, which means the same server that hosts this site. It may not be as fast as downloading it from Google, but at least we know that it will work.
source share