Especially when you are reusing JavaScript code on your website, an external JavaScript file (or several files) comes in handy. This external file contains only the JavaScript code, no <script> elements. A <script> element is, however, used to load the external file, as can be seen from the previous listing (file scriptsrc.html). The src attribute holds the URL of the external script; absolute URLs (and, therefore, remote servers) are also possible. Warning Note that the code in the external file is available only after the external file has been fully loaded. So especially when calling functionality in the external file from the local page, keep in mind that the external file may not be available yet. |