[whatwg] Proposal for separating script downloads and execution

Glenn Maynard glenn at zewt.org
Tue Feb 22 17:54:24 PST 2011


On Tue, Feb 22, 2011 at 8:14 PM, Kyle Simpson <getify at gmail.com> wrote:

>  First of all, which two proposals are we talking about here?
>>
>
> 1. Nicholas' proposal, which is currently to "preload" a script if its
> script element is marked with a `preload` attribute, before the setting of
> the `src` property. To "execute" the script, you add the script element to
> the DOM. To detect when the preload finishes, you listen to the `onpreload`
> event.
>
> 2. My proposal, which is (by and large) to standardize the functionality
> that IE already has, and that the spec already suggests, which is that
> preloading happens when setting the `src` property before adding the script
> to the DOM. To "execute", add the script to the DOM. TO detect when the
> preload finishes, listen for the `onreadystatechange` event to signal that
> the `readyState` property is "loaded".
>

To briefly restate the third proposal, so it's not lost in the noise:

3. My (and Nicholas's previous) proposal: Script elements are fetched when
inserted into the DOM[1].  An event is dispatched when the script has been
fetched, eg. "onfetch" or "onpreload"[2].  A "preload" attribute is added;
when true, the script will not be executed when the fetch completes; call
script.execute() to run the script.

Aside from what I think are a lot of advantages of this approach, it avoids
the issues behind mimicing the "src" behavior of images.  It seems that's a
bad precedent to follow--it's a compatibility hack, not something that
should be copied.


[1] Not to imply prohibiting IE's behavior of prefetching when src is set.
This is just to contrast from #1 and #2: it doesn't become a requirement.
[2] The proposal suggested "onpreload", but there's no actual need for the
"script fetched" event to be tied to preloading.  I think "onfetch" makes
more sense.

-- 
Glenn Maynard



More information about the whatwg mailing list