[whatwg] Script loading and execution order for importScripts

Oliver Hunt oliver at apple.com
Fri Mar 6 20:40:20 PST 2009


So I've been looking at importScripts (http://www.whatwg.org/specs/web-workers/current-work/#importing-scripts-and-libraries 
  ) and found that the behaviour of Mozilla differs from the behaviour  
defined in the spec.  The spec behaviour is

(pseudo code, skipping url validation, etc)
function importScripts(sources) {
     for (source in sources) {
         script = loadScript(source);
         if (load failed)
              throw NETWORK_ERR
         execute(script);
     }
}

This means that any scripts specified before the failing resource load  
will have executed, whereas Mozilla's behaviour appears to be:
function importScripts(sources) {
     scripts = [];
     for (source in sources) {
         script = loadScript(source);
         if (load failed)
              throw NETWORK_ERR
         scripts.push(script);
     }
     for (script in scripts)
         execute(script)
}

Which means that none of the scripts will execute if any script fails  
to load.

In all honesty i'm not sure which is the better approach as the spec  
approach requires developers to manually handle the potential for  
partial library execution, but the Mozilla approach removes the  
ability to load and execute scripts in parallel, which may cause  
latency problems.

Does anyone else have any thoughts as to whether the spec should be  
changed to match Mozilla behaviour, or whether the Mozilla behaviour  
should be considered "incorrect"?

--Oliver




More information about the whatwg mailing list