Completion requirements
View
6. Where to place the <script> element?
Typically, the <script> element is placed in the document header and/or at the very end of the
body, and goes anywhere in the document. Sprinkling the script through the document is not
recommended, as it would be hard to locate and maintain.
The end of the document, just before the </body> tag, is the recommended placement for
most scripts, since the document and its DOM structure will be parsed by the browser. The
information would then be ready and usable by the time it gets to the scripts and they can execute
faster. In addition, moving the script to the bottom improves the perceived performance, simply
because the download and execution of the script blocks the page’s rendering.