How to use an external JavaScript file?

How to use an external JavaScript file?

External JavaScript files are files that are saved with a .js extension. These files can be embedded into an html page, hence allowing one to use JavaScript functions on an html page. The benefit of using an external JavaScript file is that it allows code reusability, i.e. one can use the same file, i.e. code in numerous html pages. It is recommended that all JavaScript files be embedded into a single file as this increases the speed of the webpage.

JavaScript files can be used to include both types of scripts, i.e. the ones placed in head (functions), and the ones places in the body, which are the ones that run when the page loads.

One significant condition in using external JavaScript files is that the file should not include the <script> tag. It should only include HTML commenting and JavaScript code.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.