External JavaScript JS File - Advantages, Disadvantages, Syntax, Attributes - Knowledge Hills
External JavaScript JS File - Advantages, Disadvantages, Syntax, Attributes - Knowledge Hills
2020 External JavaScript JS File - Advantages, Disadvantages, Syntax, Attributes - Knowledge Hills
☰
(http://knowledgehills.com)
Step 2. To use an external script in page, type the path of the script file in the src attribute of <script> tag as below. The src
attribute can be a relative path if the file is hosted on the same server where the html file is. Or it can be a fully qualified
url if the js file is hosted on a different web server.
<html>
<body>
<p id="div_id">Welcome to Javascript</p>
<script src="/Code-Samples/JavaScript/myScript.js"></script>
</body>
</html>
http://knowledgehills.com/javascript/external-javascript-syntax-disadvantages.htm 2/3
5.09.2020 External JavaScript JS File - Advantages, Disadvantages, Syntax, Attributes - Knowledge Hills
When script1 and script2 are loaded in that order with defer, then script1 is guaranteed to execute first
Then script2 will execute a er script1 is fully executed
Must do this if script2 depends on script1
If your script is small enough and is depended by by another script of type async then use your script with no
attributes and place it above all the async scripts.
<<< Adding JavaScript to html (http://knowledgehills.com/javascript/where-should-the-javascript-be-placed-inside-a-html-page.htm)
JavaScript Syntax >>> (http://knowledgehills.com/javascript/javascript-syntax.htm)
http://knowledgehills.com/javascript/external-javascript-syntax-disadvantages.htm 3/3