+ 1
Guys, what is the difference between putting the <script> tags in the <head> and the <body> tags?
4 Réponses
+ 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 )...
+ 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.
+ 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
- 2
script