Re: [whatwg] Feedback on Web Worker specification

Hi Elliot,

Thank you for the suggestion.  Using the <script> element seems like a good
approach to explore.

Overloading the 'type' attribute could be problematic because the script type
may well be orthogonal to the JS context to which the script applies.  Could I
suggest a new attribute, for example 'context' that declares the script context.

I presume allowing multiple script elements to declare code for a single worker
would be a complex a thread synchronization problem and thus might be best
avoided?

If so then using the element id seems ok.  Otherwise perhaps giving the workers
a name would be better so that multiple script elements could declare code for
a particular worker?  Or could the 'class' attribute suit?

For example:
<script type="text/javascript" context="worker" name="taskQueue1">
...
</script>

<script type="text/javascript" context="worker" name="taskQueue1">

...more...

</script>


If the starting of the worker could be deferred until the page had all loaded then
perhaps the above usage could be thread safe.

I presume allowing the document JS to inject new script elements for a worker
would also be a complex thread synchronization problem and might also be best
avoided?

For the use case I have in mind the worker needs to be created from only static
markup so such a restriction would suit.

Supporting the 'src' attribute would also be useful, particularly for pages using a CSP.
For example:
<script type="text/javascript" context="worker" name="taskQueue1" src="taskqueue1.js"></script>

cheers
Fred


> From: esprehn@chromium.org
> Date: Tue, 20 Nov 2012 23:49:00 -0500
> To: ian@hixie.ch
> CC: whatwg@whatwg.org
> Subject: Re: [whatwg] Feedback on Web Worker specification
> 
> On Tue, Nov 20, 2012 at 6:30 PM, Ian Hickson <ian@hixie.ch> wrote:
> 
> > ...
> > On Sat, 3 Nov 2012, Fred Andrews wrote:
> > >
> > > Feedback and suggestions for appropriate markup to declare web workers
> > > would be appreciated.
> >
> > Workers are only usable from script, so just start them in script. No need
> > for anything declarative.
> >
> 
> This has come up a couple times with developers and I think being able to
> do:
> 
> <script type="worker" id="taskQueue">
>   ...
> </script>
> 
> and then being able to access the worker to post message it by id would be
> extremely useful.
> 
> document.getElementById('taskQueue').worker.postMessage(...);
> 
> Forcing the code into a separate file or requiring a data URL is annoying.
> 
> - E

 		 	   		  

Received on Thursday, 22 November 2012 00:16:44 UTC