Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <script> async Attribute

The 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.

This only works for external scripts.

Example

#

An async attribute on a <script> element.

<script src="/tutorial/script-async.js" async>
</script>

Script file

Here is the script-async.js script file. It displays an alert box when executed.

alert("This alert is executed asynchronously.");

Using async

The 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:

  • no attribute - Default: the script is fetched an executed right away, even before the page loads.
  • async - Asynchronously: the script will be executed when available, as the page loads.
  • defer - Deferred: executes the script only when the page has been completely loaded.

Syntax

<script src="URL" async>

Browser support

Here is when async support started for each browser:

Chrome
8.0 Dec 2010
Firefox
3.6 Jan 2010
IE/Edge
10.0 Sep 2012
Opera
15.0 May 2013
Safari
5.1 Oct 2011

You may also like

 Back to <script>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides