Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

async="async" attribute of a <script> tag in html, What does it mean?

async="async" attribute of a <script> tag in HTML, What does it mean?

<script async="async" src="...."></script> 

Can be see used here for example

like image 488
Itay Moav -Malimovka Avatar asked May 22 '09 00:05

Itay Moav -Malimovka


People also ask

What is async attribute in script tag?

The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available. Note: The async attribute is only for external scripts (and should only be used if the src attribute is present).

What are async scripts?

Asynchronous code: Scripts are loaded and executed parallelly in one go, wherein scripts are loaded concurrently as other web page components. Asynchronous scripts do not wait for other functions or statements to be executed.

What are defer and async attributes on a script tag?

Defer attribute is useful when script is using for DOM manipulations. Means script will apply on document html. async attribute: It will download the script file and execute without wait the end of html parsing. In other words, It will not guarantee all the scripts will execute after the html parsing.

What is the benefit of adding async to script as attributes?

And according to Steve Souders site, "the main benefit of this [async attribute] is it tells the browser that subsequent scripts can be executed immediately – they don't have to wait for ga. js".


1 Answers

If the async attribute is set on an external script (one with src=), browsers that support it will download that script in the background without blocking the rest of the content on the page. The script will execute whenever it is finished downloading.

http://dev.w3.org/html5/spec/Overview.html#attr-script-async

As I mentioned in a comment, setting async=true, async=false or async=anything all mean the same thing. They enable the async behavior. The only way to make a script non-async is to completely omit the attribute.

http://dev.w3.org/html5/spec/Overview.html#boolean-attributes

like image 120
Brian Avatar answered Sep 20 '22 11:09

Brian