Guys, what is the difference between putting the <script> tags in the <head> and the <body> tags? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Guys, what is the difference between putting the <script> tags in the <head> and the <body> tags?

14th Mar 2018, 2:28 PM
Mike Onyando
Mike Onyando - avatar
4 Answers
+ 3
Where <script> tags are localized doesn't change the loading time, but change when <script> content are loaded ( if external file linked ) and parsed... However, where <script> tags are localized could change the displaying time of the page content. Html source code is linearly parsed, so when a <script> tag is encountered, parsing of following code is suspended while the <script> content is loaded and executed. If the <script> content is embeded ( not external file linked ), the displaying time of following html content is increased by the <script> content execution. If the <script> content is externaly linked, the displaying time of following html content is also increased by the external file loading time ( but the page load time will not change: there's as much data to load before the page will be fully loaded -- when 'onload' window event is called )...
14th Mar 2018, 5:56 PM
visph
visph - avatar
+ 2
Placing <script> tag in <head> tag makes your page load faster and fully where placing in <body> won't load pages fast. Also it is a good practice to put script tag inside head tag.
14th Mar 2018, 3:08 PM
Pravin Pandey
Pravin Pandey - avatar
+ 1
placing script tag in the head tag is specified but it could happen when placed in body some fun wouldn't run or cause run time error
15th Mar 2018, 10:12 AM
Ayush
Ayush - avatar
- 2
script
14th Mar 2018, 4:59 PM
Bogdan Kryt