{"action":"created","issue":{"url":"https://api.github.com/repos/slightlyoff/BackgroundSync/issues/70","labels_url":"https://api.github.com/repos/slightlyoff/BackgroundSync/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/slightlyoff/BackgroundSync/issues/70/comments","events_url":"https://api.github.com/repos/slightlyoff/BackgroundSync/issues/70/events","html_url":"https://github.com/slightlyoff/BackgroundSync/issues/70","id":65590026,"number":70,"title":"Guidance on background sync and shared workers","user":{"login":"jrburke","id":73359,"avatar_url":"https://avatars.githubusercontent.com/u/73359?v=3","gravatar_id":"","url":"https://api.github.com/users/jrburke","html_url":"https://github.com/jrburke","followers_url":"https://api.github.com/users/jrburke/followers","following_url":"https://api.github.com/users/jrburke/following{/other_user}","gists_url":"https://api.github.com/users/jrburke/gists{/gist_id}","starred_url":"https://api.github.com/users/jrburke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrburke/subscriptions","organizations_url":"https://api.github.com/users/jrburke/orgs","repos_url":"https://api.github.com/users/jrburke/repos","events_url":"https://api.github.com/users/jrburke/events{/privacy}","received_events_url":"https://api.github.com/users/jrburke/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2015-04-01T02:50:13Z","updated_at":"2015-04-14T17:41:23Z","closed_at":"2015-04-14T17:41:23Z","body":"Andrew Overholt of Mozilla suggested I post here about use cases that come up in the context of Firefox OS and service workers that want to do background sync. It may help with the use case document.\r\n\r\n### Context\r\n\r\nThe email app on Firefox OS. It wants to do background syncs every so often when there is connectivity available. The user indicates a rough time interval (5 mins, 10 minutes, 15 minutes, 30 minutes, 1 hour). The sync interval does not have to be exact, just approximate to those intervals, and only if there is connectivity available.\r\n\r\nBackground sync is used instead of something like a push API-backed server because it is a generic email application that can connect to IMAP/ActiveSync/POP3 servers that likely do not have support for push.\r\n\r\nFirefox OS apps can have multiple browser windows opened per app, so the email app would want to use a shared worker to do the network and IndexedDB work for syncing and for handling serving slices of the email data to the browser windows. We just what one entity responsible for the network connections and data services, and holding the business logic related to the data models.\r\n\r\n### Issue\r\n\r\nThis gets a bit tricky though when considering a service worker with a background sync entry point:\r\n\r\n* The sync could come in and there could be no open email windows, so the shared worker may not be spun up yet.\r\n* Or, the background sync could come in while there is an open email window, and the shared worker is available.\r\n\r\nHowever, service workers spinning up shared workers did not seem to be allowed, if I read the old issues list for service workers correctly.\r\n\r\nSo guidance on this use case is appreciated. Here are some things that were discussed when talking about the issue within our group:\r\n\r\n### Possibilities\r\n\r\n**Talk to shared worker**: Maybe there is a way for the background sync entry point to communicate to the shared worker, and start up the shared worker if not running, and wait for it to complete its network and database work before signaling the sync is complete.\r\n\r\nHowever, it is my understanding that this is not allowed in a service worker at the moment.\r\n\r\n**Service worker as the backend**: Use the service worker as the shared worker, so embedding the code for the sync work in the service workers, and the user visible browser windows for the app would talk to it for the data slices.\r\n\r\nHowever, we do not want to burden the service worker with more work, where it might interfere or slow down the service worker handling its basic fetch duties. Plus, the service worker seemed volatile, and not really designed to be more long-lived for use by user visible browser windows for business logic/data services for the UI.\r\n\r\n**openWindow**: Perhaps the service worker could use [openWindow](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#clients-openwindow) to open a non-visible browser window that would then talk to/spin up the shared worker.\r\n\r\nHowever, it is unclear if those windows would be user visible or not. In this case we would not want that window visible as it is just a pipeline to spin up the shared worker, and that window needs to be destroyed at some point. It seems like a better expression of intention to just spin up the shared worker directly, as something that is not visible and just related to data processing.\r\n"},"comment":{"url":"https://api.github.com/repos/slightlyoff/BackgroundSync/issues/comments/92992724","html_url":"https://github.com/slightlyoff/BackgroundSync/issues/70#issuecomment-92992724","issue_url":"https://api.github.com/repos/slightlyoff/BackgroundSync/issues/70","id":92992724,"user":{"login":"jrburke","id":73359,"avatar_url":"https://avatars.githubusercontent.com/u/73359?v=3","gravatar_id":"","url":"https://api.github.com/users/jrburke","html_url":"https://github.com/jrburke","followers_url":"https://api.github.com/users/jrburke/followers","following_url":"https://api.github.com/users/jrburke/following{/other_user}","gists_url":"https://api.github.com/users/jrburke/gists{/gist_id}","starred_url":"https://api.github.com/users/jrburke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrburke/subscriptions","organizations_url":"https://api.github.com/users/jrburke/orgs","repos_url":"https://api.github.com/users/jrburke/repos","events_url":"https://api.github.com/users/jrburke/events{/privacy}","received_events_url":"https://api.github.com/users/jrburke/received_events","type":"User","site_admin":false},"created_at":"2015-04-14T17:41:23Z","updated_at":"2015-04-14T17:41:23Z","body":"This use case has been explored, and it looks like slightlyoff/ServiceWorker#678 will be enough to support it, closing this ticket."}}