The async attribute is a boolean attribute and specifies that the script will be executed asynchronously once it is available. It only works for external scripts and must be used only when the src attribute is present.
You can use the async attribute on the <script> element.
An external script can be executed in the following ways:
- When async is present, the script will be executed asynchronously while the page continues the parsing.
- When async is not present but defer is present, the script will be executed when the page finishes the parsing.
- When neither async or defer is present, the script will be executed immediately before the browser continues the parsing.
<script src="example.js" async></script>
Example of the HTML async attribute: