Re: [whatwg] Script preloading

On Aug 30, 2013, at 5:54 PM, Glenn Maynard <glenn@zewt.org> wrote:

> I don't like the name "jit", because it already has a different meaning when talking about scripting.  If this was for CSS or WebVTT or something else other than scripts, it wouldn't be as bad...
> 
> On Fri, Aug 30, 2013 at 7:22 PM, Ryosuke Niwa <rniwa@apple.com> wrote:
> I don't quite understand why we need two values for "whenneded".
> 
> Why can't we simply have "prefetch" (since we already use that term in the link element) and "needs" (I'd prefer calling it "requires") content attributes?
> 
> When a script element has the prefetch attribute, it doesn't execute until execute() is called upon the element unless
> (i.e. the script is executed immediately when the script has been loaded) if at least one of its dependencies is not a prefetch
> (i.e. doesn't have the "prefetch" content attribute).
> 
> I'm not sure what you mean (skipping the parenthetical this says "unless if", so I'm not sure how to parse that), but "prefetch" sounds like something different than "jit".

Yes.  "Prefetch" is like "noexecute" if there are no dependencies that require immediate execution.  But it behaves like "jit" if there are dependencies.

Example 1.
<script src="A.js" prefetch></script>
<script src="B.js" requires="C.js" prefetch></script>
<script src="C.js" prefetch></script>
Neither A.js, B.js, nor C.js are executed until execute() is called on each element.

Example 2.
<script src="A.js" prefetch></script>
<script src="B.js" requires="C.js"></script>
<script src="C.js" prefetch></script>
Both C.js and B.js are executed respectively once they're loaded since C.js requires B.js.

Example 2.
<script src="A.js" prefetch></script>
<script src="B.js" requires="C.js"></script>
<script src="C.js" requires="A.js" prefetch></script>
A.js, C.js, B.js are executed respectively because "B.js" requires "C.js" that in turn requires "A.js"

> The use case was "download several scripts, then execute them all at once".  I'm not sure about that use case, but a prefetch hint doesn't seem right for that.  You'd end up downloading the scripts even if they're never used.

There was a use case for fetching a script without ever executing them until execute() is called.

I'll argue, however, that UAs should have the option NOT to fetch such a script immediately based on the network condition, bandwidth, etc...  That's why I like the name "prefetch" because it implies a weak requirement.

Another problem I'm interested in hearing Web developer's opinion is how we can manage the priority of resource requests.  e.g. scripts only used for some obscure feature on a page can be requested later;  Web browser should be able to prioritize requests for the page's main assets such as the tile image, web fonts, etc...

- R. Niwa

Received on Saturday, 31 August 2013 01:14:23 UTC