W3C home > Mailing lists > Public > public-html@w3.org > October 2010

Re: Executing script-inserted external scripts in insertion order

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 12 Oct 2010 19:09:40 +0000 (UTC)
To: Getify <getify@gmail.com>
cc: public html <public-html@w3.org>
Message-ID: <Pine.LNX.4.64.1010121901350.8618@ps20323.dreamhostps.com>
On Tue, 12 Oct 2010, Getify wrote:
>
>   b) figure out how to load in parallel, but execute serially (if the 
> need is expressed). This is what LABjs figured out how to do, and what 
> RequireJS+order plugin does. It's the ideal balance of script loading 
> performance with flexibility of where files are hosted, caching 
> behavior, etc.

So it seems that this is possible today quite easily: first prime the 
browser's cache with all the scripts using one of the techniques described 
below, and then when you want to start running the script, insert them one 
at a time into the document, using the "onload" event handler to figure 
out when to load the next one.

The "right" way to do cache priming is to explicitly use <link 
rel=prefetch>. As I understand it, not all browsers support rel=prefetch; 
but it turns out there's a bunch of hacks one can do already to prime the 
cache: using an <img> or an <iframe>, for example. So instead of 
rel=prefetch, you can use one of those mechanisms. (In some browsers, as 
you've seen, <script type="bogus"> is another way to do it. However, that 
interferes with the point of the type="" attribute, which is to give the 
browser a hint about whether there's any point downloading the file or 
not, so I wouldn't recommend using that. It's also non-conforming to 
specify the wrong type, since normally it indicates an authoring mistake.)

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 12 October 2010 19:10:12 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:17:15 GMT