W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2007

[whatwg] Apply script.defer to internal scripts

From: Stewart Brodie <stewart.brodie@antplc.com>
Date: Tue, 3 Apr 2007 15:07:53 +0100
Message-ID: <b1d94a5289ca65c2f6a4a40508c8e4b14fc362ca@localhost>
"Hallvord R M Steen" <hallvors at gmail.com> wrote:

> On 27/03/07, Kristof Zelechovski <giecrilj at stegny.2a.pl> wrote:
> 
> > 3.17.1. The script element specification says:
> >
> > defer (if the src attribute is present)
> >
> > async (if the src attribute is present)
> > I understand that the async attribute must depend on the src attribute
> > because it is needed and meaningful only when the script element is
> > loaded from an external source; however, the advantage of using the
> > defer attribute is not limited to that case.
> 
> There is no real advantage to the defer attribute since in HTML4 it is
> only advisory, the UA is not required to actually defer the script
> execution, and some implementations only defer it until seeing the
> next SCRIPT element in the source. Relying on it the way your use case
> does will work in very few browsers, and specifying this in HTML5
> would increase backwards incompatibility for a very minimal gain.

My implementation will execute the script immediately if it was inline, and
execute it as soon as the whole script is available (obtained from
filesystem/network) otherwise.  As far as I understood the specification,
the DEFER simply indicates to the HTML parser that it can continue parsing
the HTML without waiting to see if the script is going to insert additional
content - i.e. the script will not use document.write (and friends).

I suspect that this facility is most useful when pages include a series of
small scripts just containing library functions.  Using DEFER permits the
browser to load them in parallel rather than in series.  I often see
auto-generated HTML pages that have a dozen or more SCRIPT elements in a row
that have been dumped in there by server-side page generators.

-- 
Stewart Brodie
Software Engineer
ANT Software Limited
Received on Tuesday, 3 April 2007 07:07:53 UTC

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