W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2010

[whatwg] script postonload

From: Steve Souders <steve@souders.org>
Date: Mon, 08 Feb 2010 14:06:07 -0800
Message-ID: <4B708ACF.1030301@souders.org>
I'd like to propose the addition of a POSTONLOAD attribute to the SCRIPT 
tag.

The behavior would be similar to DEFER, but instead of delaying 
downloads until after parsing they would be delayed until after the 
window's load event. Similar to DEFER, this new attribute would ensure 
scripts were executed in the order they appear in the document, although 
it could be combined with ASYNC to have them execute as soon as the 
response is received.

Developers can do this now using JavaScript, but it's complex and 
errorprone. For example, how should the script be added to the document? 
People typically append to the 'head' element, but some pages don't have 
a 'head' element and some browsers don't create a default one. And 
'documentElement' doesn't work in all browsers either. The safest path 
I've seen is to append to ( head || body ). Whether everyone agrees this 
is best, it reveals the complexity developers will have to consider.

Adding this attribute would lower the bar promoting this best practice 
for making web pages faster.

-Steve
Received on Monday, 8 February 2010 14:06:07 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:55 UTC