[whatwg] SharedWorkers and the name parameter
Drew Wilson
atwilson at google.com
Fri Aug 14 11:06:30 PDT 2009
Currently, SharedWorkers accept both a "url" parameter and a "name"
parameter - the purpose is to let pages run multiple SharedWorkers using the
same script resource without having to load separate resources from the
server.
Per section 4.8.3 of the SharedWorkers spec, if a page loads a shared worker
with a url and name, it is illegal for any other page under the same origin
to load a worker with the same name but a different URL -- the SharedWorker
name becomes essentially a shared global namespace across all pages in a
single origin. This causes problems when you have multiple pages under the
same domain (ala geocities.com) - the pages all need to coordinate in their
use of "name". Additionally, a typo in one page (i.e. invoking
SharedWorker("mypagescript?", "name") instead of
SharedWorker("mypagescript", "name") will keep all subsequent pages in that
domain from loading a worker under that name so long as the original page
resides in the page cache.
I'd* like to propose changing the spec so that the name is not associated
with the origin, but instead with the URL itself.
So if a page wanted to have multiple instances of a SharedWorker using the
same URL, it could do this:
new SharedWorker("url.js", "name");
new SharedWorker("url.js", "name2");
Nothing would prevent a page from also doing this, however:
new SharedWorker("other_url.js", "name");
So step 4 in section 4.8.3 would change from this:
If there exists a SharedWorkerGlobalScope <#sharedworkerglobalscope> object
whose closing <#dom-workerglobalscope-closing> flag is false, whose
name attribute
is exactly equal to the name argument, and whose
location<#dom-workerglobalscope-location> attribute
represents an absolute URL that has the same origin as the resulting absolute
URL, then run these substeps:
to this:
If there exists a SharedWorkerGlobalScope <#sharedworkerglobalscope> object
whose closing <#dom-workerglobalscope-closing> flag is false, whose
name attribute
is exactly equal to the name argument, and whose
location<#dom-workerglobalscope-location> attribute
represents an absolute URL that exactly matches the resulting absolute URL,
then run these substeps:
The downside of this change is pages might inadvertently create a second
instance of a SharedWorker if they inadvertently use the wrong URL. It seems
like this is an acceptable tradeoff given the problems described above.
What do people think of this?
-atw
* Thanks to Darin Adler for suggesting this solution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090814/e168618a/attachment-0002.htm>
More information about the whatwg
mailing list