When to use the tag in the head and body section of a html page? [duplicate]

Scripts in <head>

Scripts to be executed when they are called, or when an event is
triggered, are placed in functions.

Put your functions in the head section, this way they are all in one
place, and they do not interfere with page content.

Scripts in <body>

If your is not placed inside a function, or if your script writes page
content, it should be placed in the body section. It is a good idea
to place scripts at the bottom of the <body> element. This can
improve page load, because script compilation can slow down the
display.

In short and simple language:

  1. Place library script such as the jQuery library in the head section.

  2. Place normal script in the head unless it becomes a performance/page
    load issue.

  3. Place script that impacts the render of the page at the end of
    the body

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)