Deaf Topics - Business Gifts - Find jobs - Find services - Submit article

PDA

View Full Version : JS placement: Beginning or at the end of the file?


enchance
May 15th 2008, 4:21 am
Which is the safer bet, to place your JS (including external JS) within the <head></head> tags or at the very end of your <body></body> tag? Or better yet, is it more efficient to simply use the code below:


<head>
<script type="text/javascript">
//Method 1:
document.body.onload = function(){
//execute all js functions
}

//Method 2: Is this even correct?
document.onload = function(){
//execute all js functions
}
</script>
</head>
<body>
</body>

Which do you prefer to use?

chenyaniv
May 15th 2008, 12:30 pm
i always put my js code in the <Head></head> part, exept the part thats importent to the website flow.

crath
May 15th 2008, 2:02 pm
I always put my code in the head tags as well.