To include an external JS file in HTML, use the <script> tag and specify the URL of the file to load. You can also specify type, defer, or async attributes to control how loading and execution occur. Typically, the <script> tag should be placed at the bottom of the <body> section to avoid blocking page rendering. </script>
How to introduce external JS in HTML
Introducing external JS files into HTML is a common practice , which allows you to organize JavaScript code into separate files and easily reuse them across multiple pages. Here's how to import an external JS file:
- Use
<script></script>
tag
Use tag to introduce external JS files. The
src
attribute of this tag specifies the URL of the script file to be loaded:
<script src="path/to/script.js"></script>
- Specifies the
type
attribute (optional)
To explicitly specify the type of file being loaded, you can use the type
attribute:
<script src="path/to/script.js" type="text/javascript"></script>
- Specify
defer
orasync
attributes (optional)
defer
and async
attributes are used to control script loading and execution Method:
-
defer
: Indicates that the script can be loaded after the page parsing is completed, but will be executed before the DOMContentLoaded event is triggered. -
async
: Indicates that the script can be loaded and executed asynchronously and is not affected by page parsing or DOMContentLoaded events.
<script src="path/to/script.js" defer></script> <script src="path/to/script.js" async></script>
- Place
<script></script>
tag

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools