-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceWorker.js
37 lines (30 loc) · 878 Bytes
/
serviceWorker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var staticCacheName = "Salman Reminder App";
self.addEventListener("install", function (e) {
e.waitUntil(
caches.open(staticCacheName).then(function (cache) {
return cache.addAll(["/"]);
})
);
});
self.addEventListener("fetch", function (event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function (response) {
return response || fetch(event.request);
})
);
});
//for push notifcation
self.addEventListener('push', function (event) {
const options = {
body: event.data.text(),
icon: 'icon.png',
badge: 'badge.png',
};
event.waitUntil(
self.registration.showNotification('Push Notification', options)
);
});
self.addEventListener('notificationclick', function (event) {
event.notification.close();
});