Increase Service Worker Life Time
I'm trying push notifications using service workers. use my own server to send notifications and eventSource is used to establish the connection. after i open the webpage service
Solution 1:
Service workers are meant to have a short lifetime, you can't make them run forever.
You could use a shared worker to do that, but they only run if your website is open.
You are trying to mix the push API and EventSource. If you use the Push API, you don't need to keep the service worker alive all the time, you can just make it execute when a push notification arrives.
Solution 2:
This is not possible and it's not the purpose of a service-worker. Why exactly do you want to keep it alive ?
Solution 3:
When you catch a push like here:
self.addEventListener('push',function(event) {
the first thing to do is to use event.waitUntil()
who takes a promise and extends the lifetime of the event and the serviceworker
self.addEventListener('push',function(event) {
event.waitUntil(<YOURPROMISE>)
}
Post a Comment for "Increase Service Worker Life Time"