Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
HTML JavaScript Script Tag

Why are javascript <script> tags placed in the <body> rather than the other script tags which are usually placed in the <head>?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. JavaScript is blocking; it is often desirable prioritise rendering HTML over loading of JS.
  2. JavaScript often needs to access elements in the DOM during its initial execution (e.g. to add event listeners). Those elements need to exist before the JS can access them. Placing the <script> element after the elements it needs to access is one way to achieve this.

The introduction of the defer attribute allows both these benefits to be gained while leaving the <script> element in the <head> which also allows the HTTP request for the JS to run in parallel. Not everybody has caught up with this development.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!