Where To Put JavaScript Code In The Web Page
In general, JavaScript can be put anywhere into the source code of a web page.
The browser runs any JavaScript it encounters while loading the web page, when it's encountered.
Therefore, JavaScript that should run early is generally put into the HEAD area of the web page source code. Otherwise (unless the nature of the JavaScript requires it to be at a certain location), the JavaScript code can be put near the bottom of the page above the cancel </BODY> tag.
For an example, let's assume the JavaScript has a timer.
If the JavaScript is put into the HEAD area of the page, the timer will start as soon as the page begins to load. If put at the bottom of the page, the timer will start when the page has nearly finished loading.
For fast loading pages, there will be little or no noticeable difference. On slow loading pages, there may be quite a bit of difference.
Put the JavaScript in the location that will work best for you.
Will Bontrager