script element. A
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
The use of comment markers is rarely required nowadays, as the browsers that do not recognise the
In XHTML, the method is somewhat different:
src="script.js" to the opening
src would be "js/script.js".
The 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.
<!DOCTYPE html> <html> <head> <title>Web page title</title> <script src="script.js"></script> </head> <body> <!-- HTML code here --> </body> </html>
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.
<!DOCTYPE html> <html> <head> <title>Web page title</title> </head> <body> <!-- HTML code here --> <script src="script.js"></script> </body> </html>
Manage research, learning and skills at defaultlogic.com. Create an account using LinkedIn to manage and organize your omni-channel knowledge. defaultlogic.com is like a shopping cart for information -- helping you to save, discuss and share.