tc39 / proposal-module-expressions

https://tc39.es/proposal-module-expressions/
MIT License
438 stars 18 forks source link

Shared workers #39

Open jakearchibald opened 3 years ago

jakearchibald commented 3 years ago

Can a module block be used to instantiate a shared worker?

const module = module { export default 42; }
cons myWorker = new SharedWorker(module, { type: 'module' });

My gut feeling is 'no', since the only way two pages could share a shared worker is by sharing the module via postMessage. That also means that two origins could end up sharing the same worker which is new and terrifying ๐Ÿ˜„.

surma commented 3 years ago

Yeah, I donโ€™t think that will work, as every Module Block is unique. So it would effectively always refer to a different module.

Akxe commented 2 years ago

I would love for this to be a thing. If the normal Worker would get this special treatment and SharedWorker would not, then I think the SharedWorker would be deprecated very soon: As it stands now, even though they are not too different the SharedWorker browser adaptation is tragic compared to the normal one.

Can a module block be used to instantiate a shared worker?

What about ServiceWorker?

May I ask, do you oppose the idea, or do you just don't think is too complicated?


I think that the https://github.com/tc39/proposal-js-module-blocks/issues/45 is a possible solution to this.