Talk:JavaScript/The SCRIPT Tag
From Wikibooks, the open-content textbooks collection
Where should the <script> tags go? What are the implications/differences between having it in <head> vs. <body>?
You can define functions, global variables, etc. in the head. You would use it in the body if you would want, for example, to use document.write to insert a custom blurb in the body of the page. If you used document.write in the head, it would replace the whole body with the string passed to it.
It may also be worth noting that officially Javascript is supposed to be used with application/x-javascript as opposed to text/javascript, however this is unsupported in some browsers. Not surprisingly, IE is one of those browsers.
--70.89.239.70 22:15, 13 November 2007 (UTC)
- See JavaScript and HTML Script Tags for a persuasive opinion piece regarding this issue. Also, here are some relevant standards:
- --Jesdisciple (talk) 23:32, 1 November 2008 (UTC)
-
- Information about where script tags can go has been updated now, including information from Yahoo's best practices for speeding up your web site regarding putting scripts at the bottom of the page.