-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceworker.js
127 lines (111 loc) · 4.55 KB
/
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
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
117
118
119
120
121
122
123
124
125
126
127
// Import Workbox CDN
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js');
if (workbox) {
console.log('Workbox berhasil dimuat!.');
// Precaching App Shell
workbox.precaching.precacheAndRoute([
{ url: '/', revision: '1' },
{ url: 'index.html', revision: '1' },
{ url: 'manifest.json', revision: '1' },
{ url: 'index.js', revision: '1' },
{ url: 'serviceworker.js', revision: '1' },
{ url: 'push.js', revision: '1' },
{ url: 'styles/libs/materialize.min.css', revision: '1' },
{ url: 'styles/custom.css', revision: '1' },
{ url: 'scripts/libs/materialize.min.js', revision: '1' },
{ url: 'scripts/libs/idb.min.js', revision: '1' },
{ url: 'scripts/utils/register-notif.js', revision: '1' },
{ url: 'scripts/utils/register-sw.js', revision: '1' },
{ url: 'scripts/utils/initiator-drawer.js', revision: '1' },
{ url: 'scripts/utils/urlBase64ToUint8Array.js', revision: '1' },
{ url: 'scripts/routes/route.js', revision: '1' },
{ url: 'scripts/routes/parse-url.js', revision: '1' },
{ url: 'scripts/view/App.js', revision: '1' },
{ url: 'scripts/view/pages/favorit-klub.js', revision: '1' },
{ url: 'scripts/view/pages/info-klub.js', revision: '1' },
{ url: 'scripts/view/pages/klasemen.js', revision: '1' },
{ url: 'scripts/view/pages/klub.js', revision: '1' },
{ url: 'scripts/view/pages/pertandingan.js', revision: '1' },
{ url: 'scripts/data/data-favorit-klub.js', revision: '1' },
{ url: 'scripts/data/data-klasemen.js', revision: '1' },
{ url: 'scripts/data/data-klub.js', revision: '1' },
{ url: 'scripts/data/data-pertandingan.js', revision: '1' },
{ url: 'images/maskable_icon-16x16-v2.png', revision: '1' },
{ url: 'images/maskable_icon-32x32-v2.png', revision: '1' },
{ url: 'images/maskable_icon-96x96-v2.png', revision: '1' },
{ url: 'images/maskable_icon-192x192-v2.png', revision: '1' },
{ url: 'images/maskable_icon_apple-192x192-v2.png', revision: '1' },
{ url: 'images/maskable_icon-512x512-v2.png', revision: '1' },
{ url: 'images/icon-mola-tv.png', revision: '1' }
]);
// Management caching API google fonts data storage in browser
workbox.routing.registerRoute(
/^https:\/\/fonts\.gstatic\.com/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'caching-api-google-fonts',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [200]
}),
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 30
}),
]
})
);
// Management caching API football data storage in browser
workbox.routing.registerRoute(
new RegExp('https://api.football-data.org/'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'caching-api-football-data',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [200]
}),
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 30
}),
]
})
);
// Management caching API image team data storage in browser
workbox.routing.registerRoute(
new RegExp('https://crests.football-data.org/'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'caching-api-image-team-football',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [200]
}),
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 30
}),
]
})
);
} else {
console.log('Workbox gagal dimuat!');
}
// Push Notification Event
self.addEventListener('push', event => {
let body;
if (event.data) {
body = event.data.text();
} else {
body = 'Pesan push tidak ada payload!';
}
event.waitUntil(
self.registration.showNotification('Notifikasi Push', {
body: body,
icon: 'images/maskable_icon-192x192-v2.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
}
})
)
})