Do you have any rules regarding the use of scripts in the head tag? W3C has not made the usage rules very clear.
Do you have any rules regarding the use of scripts in the head tag? W3C has not made the usage rules very clear.
Because the main elements of the page, which should be the most relevant, can already be rendered before the end of the verification and interpretation of the parts in JS, which are usually important only after the page loads.
If the JS code is placed at the beginning or middle, page rendering is obstructed until all script is parsed.
Obviously this does not work so well in all cases. It may be that correct and complete rendering is only possible when script starts to run.
There are a number of techniques to better control this load and in a few cases this recommendation should be followed.
Then nothing prevents and in general put tag head
is advantageous, especially if loading asynchronously or with delay:
<script defer>
or
<script async>
See how it works .