Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<script> Block in Html

 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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?





Thanks,
ABU.A



 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Eric
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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'


This is the whole idea. Right?

Abu.A
 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great.. I got it..

Thanks Eric, Bear.
Abu.A
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic