Closed piranna closed 10 years ago
Regarding SharedWorkers creating ServiceWorker: It doesn't matter who "created" the serviceworker - the persistence/lifetime issues are around matching urls. In fact, it's really up to the user agent to "create" the serviceworker when it decides it is necessary.
Regarding ServiceWorker creating SharedWorkers: I personally think that SharedWorkers created from ServiceWorkers won't stay open. They need a live document to stay open, and a SharedWorker is not that. This would also result in rather unpredictable behavior for SharedWorkers if a user agent decides to aggressively kill ServiceWorkers - that could mean that SharedWorkers are going up and down and being killed all the time as well.
I'd even argue that you shouldn't be able to create a SharedWorker, for exactly this reason.
I agree, allowing the creation of SharedWorkers from ServiceWorkers will lead down a big rabbit hole. This should be something kept for far in the future if enough solid use cases come up.
So do you both think that ServiceWorkers shouldn't behave as a "web page" regarding to the SharedWorker lifecycle, and only take in account real documents, isn't it? Should then someone that want to use the functionality of SharedWorkers and ServiceWorkers at the same time just use only the ServiceWorker?
I just don't see the use cases versus the complexity of reasoning and implementation for both browser devs and webdevs.
I admit doesn't have too much clear this corner case, and I'm thinking in other alternatives for this use case, only I'm not still sure what's the best one yet.
I'm going to leave this open until it's in the spec language, buy my decision here is to explicitly prevent SW's from creating Shared Workers. Given that this will also prevent them from messaging Shared Workers, I think we need to re-visit discovery, but this doesn't seem pressing.
Even if you disable creation, you can still hand its message channel around which is effectively the same issue.
One thing to keep in mind is that currently no browser support creating SharedWorkers from within any type of workers. So I doubt that SharedWorkers within ServiceWorkers is going to be implemented very soon.
Shared workers live as long as the execution contexts that have references to them. SW's don't live very long, so if you hold on to them, it's not going to do what you expect. Hold SW's from Documents ;-)
SharedWorkers keep living while there'sa web page of the domain that created it open. Since all WebWorkers can create others, and ServiceWorkers live without needing a web page open, I think: if a ServiceWorker create a SharedWorker, should this keep living and consider its parent ServiceWorker as one of those "open web pages"? And if the SharedWorker is created by a web page or a WebWorker from the same domain that a currently registered ServiceWorker? I believe the answer for both questions is 'yes'.