- Create a new .html file in your text editor of choice.
- Inside the
<head>tag of your HTML file, add a script tag with the
<script>tag. This can be inside the
<head> <script src="path/to/your/script.js"></script> </head>
Additionally, here are some best practices to keep in mind:
- Not defining the language attribute: The language attribute in the script tag tells the browser what kind of script it is. If you don’t define this attribute, the browser won’t know how to parse the script. Although modern browsers can detect the language automatically, it is still important to define the attribute for older browsers.
However, this method isn’t recommended as it can clutter your HTML code and make it disorganized.
This method is ideal for small projects with just a few pages. However, for larger projects, it can be time-consuming to add the script tags to each page.
This method is ideal for large projects that have many pages, as the same script file can be linked to multiple pages.
Please find the code below: