0

What's the difference between putting script in <head> and <body>?

21st Nov 2016, 2:28 AM
Jeho
3 odpowiedzi
+ 2
I don't think it'll change anything as far as how the program runs.
21st Nov 2016, 2:37 AM
Keto Z
Keto Z - avatar
+ 1
there is no significant difference when you put script in head it is one place and does not get mixed there with webpage. but in this case sometime the element it is referring to hasn't yet loaded so scripts are either placed in body after elements which take time in loading slowly or all the scripts is put in document.onload listener in this way they run only when document is loaded. or listener can be attached to the elements
21st Nov 2016, 3:21 AM
Sandeep Chatterjee
+ 1
@Sandeep Chatterjee is right, scripts are generally placed at the END of <body> - simply due to the fact that the scripts run when loaded. If this is in <head> then the script will run early in the loading process and can cause delays in the page loading through.
21st Nov 2016, 7:41 AM
Pink Lemonade