aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes <script> Block in Html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "<script> Block in Html" Watch "<script> Block in Html" New topic
Author

<script> Block in Html

Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Aug 12, 2009
Posts: 90

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
http://developer.yahoo.net/blog/archives/2007/07/high_performanc_5.html

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Great.. I got it..

Thanks Eric, Bear.
Abu.A
 
jQuery in Action, 2nd edition
 
subject: <script> Block in Html