-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
116 lines (109 loc) · 2.25 KB
/
service-worker.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js');
workbox.setConfig({
debug: false
});
workbox.core.skipWaiting();
workbox.core.clientsClaim();
// set cache names
workbox.core.setCacheNameDetails({
prefix: 'my',
suffix: 'v1',
precache: 'appshell',
});
// Precaching all assets first
// Automatic for event activite and fetch from cache
workbox.precaching.precacheAndRoute([
'css/materialize.min.css',
'js/idb.js',
'js/materialize.min.js',
'images/images_unavailable.png',
{
url: 'index.html',
revision: '1'
},
{
url: 'nav.html',
revision: '1'
},
{
url: 'team.html',
revision: '1'
},
{
url: 'manifest.json',
revision: '1'
},
{
url: 'css/style.css',
revision: '1'
},
{
url: 'js/api.js',
revision: '1'
},
{
url: 'js/db.js',
revision: '1'
},
{
url: 'js/index-script.js',
revision: '1'
},
{
url: 'js/nav.js',
revision: '1'
},
{
url: 'js/team-script.js',
revision: '1'
},
{
url: 'pages/home.html',
revision: '1'
},
{
url: 'pages/saved.html',
revision: '1'
}
], {
// Ignore all URL parameters.
ignoreURLParametersMatching: [/.*/],
});
// Clean Up Old Precaches
workbox.precaching.cleanupOutdatedCaches();
// Using stale while revalidate
workbox.routing.registerRoute(
new RegExp("https://api.football-data.org/v2/.+"),
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'data',
plugins: [
new workbox.expiration.Plugin({
// Max 100 entries
maxEntries: 100,
// Max 7 days caching
maxAgeSeconds: 7 * 24 * 60 * 60,
}),
],
})
);
// Push event for notification
self.addEventListener('push', function (event) {
var body;
if (event.data) {
body = event.data.text();
} else {
body = 'Pesan default.';
}
var options = {
body: body,
icon: 'images/icons/icon-128x128.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
}
};
event.waitUntil(
self.registration.showNotification('Pemberitahuan!', options)
);
});