We can place JavaScript in 3 ways?
- as a external file
- in
<head>
- in body
<body>
all methods are valid by W3C ?
So How to judge where JavaScript should be placed at bottom or which must be in <head>
or in <body>
?
- I've seen JavaScript on many sites
- in
<head>
, - as a external js,
- just before
</body>
and - some time anywhere in
<body>....<body>
for example: before any other XHTML tag/code which are going to affect with that JavaScript code.
update: I saw mostly people use Google analytics code as a inline javascript at bottom?