<script> Attributes: async

By: Dusty Arlia
Published on Sunday, March 16, 2014, 10:00 PM
Last Updated on Sunday, July 05, 2015 at 4:08 PM
Total Updates: 4

The HTML <script> tag has an async attribute that mirrors the async property of the Script JavaScript object. The async attribute is a boolean attribute. What this means is it doesn't have a value, it just needs to be present. If the async attribute is present, then the script will run asynchronously. If a script is running asynchronouly, then it means that other things can be running at the same time. The async attriute causes the browser to run the script as soon as possible, but not to block document parsing while the script is being downloaded. Asynchronous scripts run as they load which means that they can execute out of order (compared to deferred scripts which run in the order in which they appear in the document).

If the async attribute is not present (and neither is a defer attribute), then the script will not run asynchronously. It will run synchronously (the default, also called a blocking script).

According to the HTML5 standard, the defer attribute and the async attribute can only be used when the src attribute is used. Some browsers may support deferred inline scripts. If both the async and defer attributes are present, the browser will use the async attribute and ignore the defer atttribute.

Comments:

Ad:

Ad: