If the script tag is above or below the body in a HTML page, does it matter for the performance of a website?
And what if used in between like this:
Along with the Performance aspect, you also need to be careful whenever you include the tag inside the tag.
Let's consider the following example:
The content of the document......
Here, notice that the script is loaded before the DOM (or the tag) is loaded, which causes a failure in the script (Since the getElementById cant find the element with name 'demo').
In such cases you have to use the script within the body tag only.
Considering the other answers, its better to have the script always before the tag as you never know whether the scripts that you would load externally have any such dependencies on your DOM.
Reference: Detailed problem description