File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes script placing 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 placing" Watch "script placing" New topic

script placing

Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
I wish to know what's the different if script in head and in body. Is there any difference on when and how the script is executed?

gave me original with error : p1 is null. can anybody explain why ? thanks
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

Well, look at the file. Does p1 exist when the script is encountered?

Some people will put the script at the end of the file, after the DOM has been constructed, and there are claims that this is more performant than other locations. (I have yet to see much of any difference.)

But most people will put initialization code in one of a load event handler, or a ready handler (if using jQuery).

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: script placing
It's not a secret anymore!