WebKit’s new attributes
Derived from KHTML, the current versions of the WebKit open source web browser engine known as "nightly builds" recognise the two attributes async
and defer
used for the HTML5 element script
. Web authors use them to influence the loading of JavaScript files. If the script was loaded traditionally via:
<script src="myFile.js"></script>
async
and defer
allows JavaScript to be loaded without blocking other elements of the page or its display. For HTML5 and XHTML, the following lines do the same:
<!-- HTML5 -->
<script async src="myFile.js"></script>
<script defer src="myFile.js"></script>
<!-- XHTML -->
<script async="async" src="myFile.js"></script>
<script defer="defer" src="myFile.js"></script>
In all cases, onload
can be used for immediate execution after loading. If async
is included, the browser loads the code (as the attribute suggests) asynchronously at the next opportunity and defer
is used to have the code loaded after the web site has been completely parsed. The browser does not necessarily load multiple scripts to be loaded via async
in the desired order; with defer
, it loads them in the order they appear in the page's text.
One of the two (defer
), which Microsoft introduced in IE4, was already contained in HTML 4.01; section 4.3 defines the use of the two attributes for HTML5. In Firefox, the attributes require Gecko 1.91. or 1.9.2.
(trk)