-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
requestIdleCallback (equivalent) for ServiceWorkerGlobalScope #790
Comments
This sounds similar to the other feedback we've heard about needing a Worker or SharedWorker from a ServiceWorker. Some work needs to be performed, but we don't want to delay handling fetch events, etc. Alternatively we could do the idea about letting multiple service workers spin up so latency is less of a concern. |
My opinion, blending in a bit of perspective writing non-blocking servers in Node.js:
|
👍 from me to the idea of offloading work to new I hadn't previous seen #678, but that looks like details the feature request, so I'll close this issue. |
I need a callback when service idle is terminated |
While using service workers, I've come across a few scenarios in which there's "low-priority" work that I'd like to perform. This work, ideally, would be performed at a time that wouldn't block core service worker functionality. Some examples of the type of work I'm talking about:
I have written code to implement both of those scenarios. In first case I run the code whenever the service worker starts up, which introduces a delay before the service worker can handle events. In the second case I run the code inside a
fetch
event handler, after theevent.respondWith()
, which introduces a delay before any subsequent events could be handled.Something akin to
requestIdleCallback
, but available within a service worker context, seems like what I'm thinking about, though that presupposes that the browser would be able to intelligently guess when a service worker is likely to be idle.Alternatively, this kind of work could be performed in a hypothetical
unload
event, but that's previously been discussed and rejected.The Background Sync API could be used for some types of work, but that feels like it's outside of the intended use case—if every service worker fired off a periodic Background Sync event just to wake up and, e.g., clean out its caches, that sounds inefficient.
Have other folks thought about appropriate eventsto hook into to do this sort of low-priority work? Is there any appetite from the spec maintainers/implementers to add in something like
requestIdleCallback
to theServiceWorkerGlobalScope
?The text was updated successfully, but these errors were encountered: