In association with heise online

21 September 2010, 15:17

WebKit’s new attributes

  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

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)

Print Version | Send by email | Permalink: http://h-online.com/-1083060
 


  • July's Community Calendar





The H Open

The H Security

The H Developer

The H Internet Toolkit