The second example is a script link to an external file called xxx.js in this case, located in the same folder as the html file. If you created this file and placed a warning in this file and moved the script block to the header tag, you will find that it will work.
Placing javascript in external files is a rewarding practice as it allows you to reuse common functions on many pages with a simple inlcude statement in your html. In addition, it saves your html files much cleaner.
When you start writing a lot of javascript, you can combine all your scripts into one file and then reduce it using something like JSMin: http://www.crockford.com/javascript/jsmin.html
This compresses all of your script into a tiny form that is not readable by people, but much faster for your website visitors, because it means the script file is smaller and there is only one request to serve the file to the client.
On the side of the note, another useful tool for writing javascript is JSLint .
It parses your javascript and informs you of syntax errors as well as bad practices.
Happy coding
Floor
Paulie waulie
source share