async attribute on a <script> tag specifies that the script is executed asynchronously, that is, whenever it is available -- irrespective of the page load progress.
async attribute on a <script> element.
<script src="/tutorial/script-async.js" async> </script>
Here is the script-async.js script file. It displays an alert box when executed.
alert("This alert is executed asynchronously.");
async attribute specifies that the script file is executed once it is available.
This attribute only works with external script files, and only when src attribute is present.
External script files can be executed in the following 3 ways:
<script src="URL" async>
Here is when
async support started for each browser:
Back to <script>