For speed purposes, I'm trying to decide whether to place my JavaScript in the <head> or just before the </body> of my site. I prefer the head and am not concerned with the extra HTTP request, just the behavior of this script.
Here are the two code snippets, which are loaded back-to-back (Google Analytics):
Script 1:
// Loaded externally:
// <script type="text/javascript" src="google_analytics_1.js"></script>
var gaJsHost = (
( "https:" == document.location.protocol ) ?
"https://ssl." :
"http://www."
);
document.write( unescape(
"%3Cscript src='" +
gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"
) );
Script 2:
// Loaded externally:
// <script type="text/javascript" src="google_analytics_2.js"></script>
try {
var pageTracker = _gat._getTracker( "UA-0000000-0" );
pageTracker._trackPageview();
}
catch( err ) { }
With the code above, does JavaScript delay sending the rest of the page until it retrieves ga.js, or does it instead say, "okay, I've got the request for ga.js queued up, now I will continue to send the rest of the page while we wait for it to download to the client..."?
My instinct tells me it is linear, and that the page will be delayed until ga.js has been completely downloaded by the client. Is that right?