<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
I have some comments and questions about the ASYNC and DEFER attributes
of the SCRIPT tag based on reading this document:<br>
<a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#script">http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html</a><br>
<br>
1. "If neither attribute is present, then the script is fetched and
executed immediately, before the user agent continues parsing the page."<br>
Thankfully, newer browsers are downloading scripts in parallel with
other resources. I presume the way this is done is they launch a
request for a script and continue to do "speculative" parsing looking
for other resources (images, stylesheets, other scripts, etc.) and
launch those requests. But this nice feature seems to be in conflict
with the above text because the browser continues parsing (albeit
speculatively) before the script is executed. It would be good to
mention this optional behavior here, something along the lines of
browsers may want to do speculative parsing, but shouldn't create DOM
elements, etc. - only kickoff HTTP requests.<br>
<br>
2. "If one or both of the defer and async attributes are specified, the
src attribute must also be specified."<br>
It should be possible to specify DEFER without a SRC. The use case
is a page that has a sequence of SCRIPTs (with and without a SRC
attribute) all of which need to execute in order, but should do so
without blocking the parser. This happens a lot with ads, widgets, and
analytics. A workaround is to use callbacks to daisy-chain the calling
sequence, but the complexity will lead most 3rd party snippet providers
to default to a normal SCRIPT tag (without DEFER or ASYNC) resulting in
blocking the parser and slow pages. It's especially annoying for web
site owners to have 3rd party content slowing down their pages and
blocking the content they've created.<br>
This appears to be a recent change perhaps prompted by Jonas
Sicking's comments that Mozilla found many web sites that specified
DEFER without a SRC and then called document.write (which pretty
clearly indicates the developer didn't mean to specify DEFER). If
that's the motivation for this restriction, we need to either find an
alternative syntax or go ahead and allow DEFER without SRC. Finding an
alternative is the worse alternative (DEFER has the exact behavior we
want, so creating something with a different name that behaves just
like DEFER is confusing). If we do move forward with allowing DEFER
without SRC, then we need to specify what happens if it contains
document.write so that the entire document isn't overwritten. (I
believe this is addressed in section 3.5.) There's no good way to make
DEFER do what it should and have those pages who are using DEFER
incorrectly work the way they do now. With this path, at least those
pages will have their content appear at the bottom and not wipe out the
entire page.<br>
<br>
3. "[the 'parser-inserted' state] is set by the HTML parser and is used
to handle document.write() calls."<br>
In what way is this used to handle document.write() calls? Is it
for handling additional SCRIPTs added via document.write, or to make
document.write itself have different behavior? The answer should be
added to the spec somewhere. I searched for .write in this document and
didn't find an explanation.<br>
<br>
4. "If the element has a src attribute, [snip] the specified resource
must then be fetched, from the origin of the element's Document."<br>
If the script has DEFER, the request should not start until after
parsing is finished. Starting it earlier could block other
(non-deferred) requests due to a connection limit or limited bandwidth.<br>
<br>
5. I don't see any rules for the order of executing scripts added to
the "list of scripts that will execute when the document has finished
parsing" and the "list of scripts that will execute as soon as
possible". DEFER scripts should execute in the order they appear in the
list. ASYNC scripts should be executed as soon as the response is
received.<br>
<br>
Thanks.<br>
<br>
-Steve<br>
<br>
<br>
</body>
</html>