Using Webworkers in angular app (service worker cache access of data in angular-cli) Using Webworkers in angular app (service worker cache access of data in angular-cli) angular angular

Using Webworkers in angular app (service worker cache access of data in angular-cli)


Yes this can be done by a service worker but :

  • The browser can terminate a service worker if it thinks the service worker has finished working. So be sure to wrap everything inside a promise and use event.waitUntil to make sure that the process isn't terminated before it has finished.

    self.addEventListener("message", function(event) { event.waitUntil(test(event));});

  • The service worker runs on a single thread, so if you do long synchronous operation you'd be slowing every request of your page. Service workers are not meant to do long calculation.

Yes shared workers can access the cache api. You can access it the same way you do from a service worker by using the global variable caches

caches.open(cacheName).then(function(cache) {      cache.match("...")});