DEV Community


Posted on

Answer: Where should I put <script> tags in HTML markup?

Here's what happens when a browser loads a website with a <script> tag on it:

  1. Fetch the HTML page (e.g. index.html)
  2. Begin parsing the HTML
  3. The parser encounters a <script> tag referencing an external script file.
  4. The browser requests the script file. Meanwhile, the parser blocks and stops parsing the…

Top comments (1)

adam_cyclones profile image
Adam Crockett

It depends. Scripts in the head will load before the body and are counted as highest priority. You can see this in the network tab of devtools assuming you have enabled displaying of this metric. Scripts in the body are low priority. So if your content absolutely depends on the script to display the page I would consider my options carefully. Scripts in head are blocking and will prevent load of other assets bellow the fold (the body).