I am curious about <script></script> placed in between Html body. Can any of you tell me what difference does it make when we place <script> tag in the html body. Why not we put it in the <head> section?
It really makes no difference where a script block is located. Only thing that is different about it is when the browser gets to it as it parses the page. It gets to it sooner when it is in the head, it gets to it later when it is in the body.
Joined: Aug 12, 2009
Meaning that if i don't want to parse all the scripts during initial start up, we can write scripts in the body. So that my browser will be fast. If I write all the scripts in the head section, the browser will get the script sooner but it will delay in the startup.
Sooner means it will load all the scripts earlier. And Later means 'the browser buys the script and eats it later whenever it needs'
Abubacker Siddik wrote:This is the whole idea. Right?
Umm, no. Script blocks placed in the body will still be evaluated up-front, just after anything else that's before it. When possible, it's best practice to place the block in the head section so that the script is evaluated and ready before the body.