devxlogo

Use External JavaScript Files

Use External JavaScript Files

If you have the same JavaScript program appearing on several different Web pages, you might want to consider using an external file. That way all the pages can refer to the same script, and if you want to change it you only need to change it in one place. It also helps keep your HTML files smaller and neater by moving the JavaScript out. External JavaScript files typically use the .js extension.

JavaScript 1.1 and later allows you to use the SRC attribute in the SCRIPT tag:

 

The file myScript.js doesn’t need any script tags, and any page with the above tag can use any of the functions and variables listed in myScript.js.

devx-admin

Share the Post: