-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
85 lines (74 loc) · 2.14 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
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js');
if (workbox)
console.log(`Workbox berhasil dimuat`);
else
console.log(`Workbox gagal dimuat`);
workbox.precaching.precacheAndRoute([
{ url: '/index.html', revision: '1' },
{ url: '/topnav.html', revision: '1' },
{ url: '/sidenav.html', revision: '1' },
{ url: '/css/materialize.min.css', revision: '1' },
{ url: '/js/materialize.min.js', revision: '1' },
{ url: '/js/nav.js', revision: '1' },
{ url: '/js/api.js', revision: '1' },
{ url: '/js/idb.js', revision: '1' },
{ url: '/icon-Small.png', revision: '1' },
{ url: '/icon-Medium.png', revision: '1' },
{ url: '/icon-Large.png', revision: '1' },
]);
// Menyimpan cache dari CSS Google Fonts
workbox.routing.registerRoute(
/^https:\/\/fonts\.googleapis\.com/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'google-fonts-stylesheets',
})
);
// Menyimpan cache untuk file font selama 1 tahun
workbox.routing.registerRoute(
/^https:\/\/fonts\.gstatic\.com/,
workbox.strategies.cacheFirst({
cacheName: 'google-fonts-webfonts',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 30,
}),
],
})
);
workbox.routing.registerRoute(
new RegExp('/pages/'),
workbox.strategies.cacheFirst()
);
// Menyimpan cache dari API football.
workbox.routing.registerRoute(
/^https:\/\/api\.football-data\.org/,
workbox.strategies.networkFirst({
networkTimeoutSeconds: 3,
cacheName: 'football-data',
})
);
self.addEventListener('push', function(event) {
var body;
if (event.data) {
body = event.data.text();
} else {
body = 'Push message no payload';
}
var options = {
body: body,
icon: 'icon-Small.png',
badge: 'icon-Small.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
}
};
event.waitUntil(
self.registration.showNotification('Push Notification', options)
);
});