Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store value in service-worker in Angular

I had created a service-worker and make it get to register. I used below code in some js file

self.addEventListener('install', function (event) {
    console.log('installing');
})
self.addEventListener('activate', function (event) {
    console.log('activating', event);
})

Can i store a variable value in angular. Like I want to store a value of 'x' in the cache by using a service worker. How can I do that?

like image 999
PRABHJOT SINGH Avatar asked Oct 16 '22 07:10

PRABHJOT SINGH


1 Answers

Use IndexedDb for this.

You can store the value in IndexedDb inside of the Service Worker and then access it inside of the Angular app. The localForage library provides a nice to user wrapper around IndexedDb, you can use this library in both your Service Worker and inside of Angular.

like image 153
Will Taylor Avatar answered Oct 24 '22 06:10

Will Taylor