async="async" attribute of a <script> tag in html, What does it mean?
The HTML WHATWG specification contains the following explanation:
For classic scripts, if the
async
attribute is present, then the classic script will be fetched in parallel to parsing and evaluated as soon as it is available (potentially before parsing completes). If theasync
attribute is not present but thedefer
attribute is present, then the classic script will be fetched in parallel and evaluated when the page has finished parsing. If neither attribute is present, then the script is fetched and evaluated immediately, blocking parsing until these are both complete.For module scripts, if the
async
attribute is present, then the module script and all its dependencies will be fetched in parallel to parsing, and the module script will be evaluated as soon as it is available (potentially before parsing completes). Otherwise, the module script and its dependencies will be fetched in parallel to parsing and evaluated when the page has finished parsing. (Thedefer
attribute has no effect on module scripts.)This is all summarized in the following schematic diagram:
The exact processing details for these attributes are, for mostly historical reasons, somewhat non-trivial, involving a number of aspects of HTML. The implementation requirements are therefore by necessity scattered throughout the specification. The algorithms [described in the HTML specification] describe the core of this processing, but these algorithms reference and are referenced by the parsing rules for script start and end tags in HTML, in foreign content, and in XML, the rules for the document.write() method, the handling of scripting, etc.
The
defer
attribute may be specified even if theasync
attribute is specified, to cause legacy Web browsers that only supportdefer
(and notasync
) to fall back to thedefer
behavior instead of the blocking behavior that is the default.
In XHTML it is needed to consequently note attributes as attributes and their values whereas HTML does not. I like the conformity of that principle so I always use it in the form of:
async="async"
This way I can serve my documents as application/xhtml+xml.
If this is not of any interest for you because you are of the opinion that serving your document as text/html is good enough, then you can always use:
async
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