script element. A
The scripting language can be specified individually in the
script element itself, and you may also use a meta tag in the head of the document to specify a default scripting language for the entire page.
Inline HTML comment markersEdit
The inline HTML comments are to prevent older browsers that do not understand the
script element from displaying the script code in plain text.
Older browsers that do not understand the
script element will interpret the entire content of the
script element above as one single HTML comment, beginning with "
<!--" and ending with "
-->", effectively ignoring the script completely. If the HTML comment was not there, the entire script would be displayed in plain text to the user by these browsers.
Current browsers that know about the
script element will ignore the first line of a
script element if it starts with "
The last line of the script, "
The use of comment markers is rarely required nowadays, as the browsers that do not recognise the
In XHTML, the method is somewhat different:
Note that both the
<![CDATA[ tags are commented out. The
// prevents the browser from mistakenly interpreting the
Linking to external scriptsEdit
src="script.js" to the opening
Location of script elementsEdit
script element may appear almost anywhere within the HTML file.
A standard location is within the
head element. Placement within the
body however is allowed.
There are however some best practices for speeding up your web site  from the Yahoo! Developer Network that specify a different placement for scripts, to put scripts at the bottom, just before the
</body> tag. This speeds up downloading, and also allows for direct manipulation of the DOM while the page is loading.
- RFC 4329: Scripting Media Types
- Yahoo: best practices for speeding up your web site