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.<div>
<br></div><div>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 <a href="http://geocities.com">geocities.com</a>) - 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.</div>
<div><br></div><div>I'd* like to propose changing the spec so that the name is not associated with the origin, but instead with the URL itself.</div><div><br></div><div>So if a page wanted to have multiple instances of a SharedWorker using the same URL, it could do this:</div>
<div><br></div><div>new SharedWorker("url.js", "name");</div><div>new SharedWorker("url.js", "name2");<br></div><div><br></div><div>Nothing would prevent a page from also doing this, however:</div>
<div><br></div><div>new SharedWorker("other_url.js", "name");</div><div><br></div><div>So step 4 in section 4.8.3 would change from this:</div><div><br></div><div><span class="Apple-style-span" style="font-family: sans-serif, 'Droid Sans Fallback'; font-size: medium; line-height: 21px; ">If there exists a <code style="font-size: inherit; font-family: monospace, 'Droid Sans Fallback'; font-variant: normal; color: rgb(255, 69, 0); "><a href="#sharedworkerglobalscope" style="color: inherit; background-image: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; ">SharedWorkerGlobalScope</a></code> object whose <a href="#dom-workerglobalscope-closing" title="dom-WorkerGlobalScope-closing" style="color: rgb(102, 0, 153); background-image: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; ">closing</a> flag is false, whose <code title="dom-WorkerGlobalScope-name" style="font-size: inherit; font-family: monospace, 'Droid Sans Fallback'; font-variant: normal; color: rgb(255, 69, 0); ">name</code> attribute is exactly equal to the <var title="">name</var> argument, and whose <code title="dom-WorkerGlobalScope-location" style="font-size: inherit; font-family: monospace, 'Droid Sans Fallback'; font-variant: normal; color: rgb(255, 69, 0); "><a href="#dom-workerglobalscope-location" style="color: inherit; background-image: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; ">location</a></code> attribute represents an <span style="border-bottom-style: solid; border-bottom-color: rgb(153, 204, 153); border-bottom-width: initial; ">absolute URL</span> that has the <span style="border-bottom-style: solid; border-bottom-color: rgb(153, 204, 153); border-bottom-width: initial; ">same origin</span> as the resulting <span style="border-bottom-style: solid; border-bottom-color: rgb(153, 204, 153); border-bottom-width: initial; ">absolute URL</span>, then run these substeps:</span></div>
<div><br></div><div>to this:</div><div><br></div><div><span class="Apple-style-span" style="font-family: sans-serif, 'Droid Sans Fallback'; font-size: medium; line-height: 21px; ">If there exists a <code style="font-size: inherit; font-family: monospace, 'Droid Sans Fallback'; font-variant: normal; color: rgb(255, 69, 0); "><a href="#sharedworkerglobalscope" style="color: inherit; background-image: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; ">SharedWorkerGlobalScope</a></code> object whose <a href="#dom-workerglobalscope-closing" title="dom-WorkerGlobalScope-closing" style="color: rgb(102, 0, 153); background-image: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; ">closing</a> flag is false, whose <code title="dom-WorkerGlobalScope-name" style="font-size: inherit; font-family: monospace, 'Droid Sans Fallback'; font-variant: normal; color: rgb(255, 69, 0); ">name</code> attribute is exactly equal to the <var title="">name</var> argument, and whose <code title="dom-WorkerGlobalScope-location" style="font-size: inherit; font-family: monospace, 'Droid Sans Fallback'; font-variant: normal; color: rgb(255, 69, 0); "><a href="#dom-workerglobalscope-location" style="color: inherit; background-image: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial initial; ">location</a></code> attribute represents an <span style="border-bottom-style: solid; border-bottom-color: rgb(153, 204, 153); border-bottom-width: initial; ">absolute URL</span> that exactly matches the resulting <span style="border-bottom-style: solid; border-bottom-color: rgb(153, 204, 153); border-bottom-width: initial; ">absolute URL</span>, then run these substeps:</span></div>
<div><br></div><div>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.</div>
<div><br></div><div>What do people think of this?</div><div><br></div><div>-atw</div><div><br></div><div>* Thanks to Darin Adler for suggesting this solution</div>