Including JavaScript Files

In addition to writing JavaScript code directly in HTML documents, you can include files of JavaScript code either from your website or from anywhere on the Internet. The syntax for this is:

<script type="text/javascript" src="script.js"></script>

Or, to pull a file in from the Internet, use:

<script type="text/javascript" src="">

As for the script files themselves, they must not include any tags, because they are unnecessary: the browser already knows that a JavaScript file is being loaded. Putting them in the JavaScript files will cause an error.

Including script files is the preferred way for you to use third-party JavaScript files on your website.

It is possible to leave out the type=”text/javascript” parameters; all modern browsers default to assuming that the script contains JavaScript.