How to define the URL of an external script file in HTML5 ?
In this article, we will learn how to define the URL of an external script file inside HTML. This may be needed when a large script code is needed to be included, and it may create confusion if all the code is written in a single file. Also, there may be a requirement for the same script to execute on different web pages, and rewriting the same code can lead to redundancy. The code can be refactored by simply writing the script code in a separate file and defining it in the HTML file.
Approach: The script tag has an attribute src which is used to specify the path of an external script file.
Example: In this example, the examplescript.js external script to be included in the HTML file.
Output: On loading the page in our browser, we will get a pop-up with the defined message which confirms that the external script has properly loaded.