-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
105 lines (101 loc) · 3.75 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
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js');
const CACHE_NAME = "footmatch-v1";
if (workbox) {
console.log(`Workbox berhasil dimuat`);
workbox.precaching.precacheAndRoute([
{ url: "/", revision: '1' },
{ url: "index.html", revision: '1' },
{ url: "nav.html", revision: '1' },
{ url: "team.html", revision: '1' },
{ url: "css/materialize.min.css", revision: '1' },
{ url: "css/style.css", revision: '1' },
{ url: "js/materialize.min.js", revision: '1' },
{ url: "js/idb.js", revision: '1' },
{ url: "js/db.js", revision: '1' },
{ url: "js/nav.js", revision: '1' },
{ url: "js/api.js", revision: '1' },
{ url: "js/notify.js", revision: '1' },
{ url: "js/team.js", revision: '1' },
{ url: "js/validate.js", revision: '1' },
{ url: "manifest.json", revision: '1' },
{ url: "images/icons/icon-512x512.png", revision: '1' },
{ url: "images/icons/icon-384x384.png", revision: '1' },
{ url: "images/icons/icon-192x192.png", revision: '1' },
{ url: "images/icons/icon-152x152.png", revision: '1' },
{ url: "images/icons/icon-144x144.png", revision: '1' },
{ url: "images/icons/icon-128x128.png", revision: '1' },
{ url: "images/icons/icon-96x96.png", revision: '1' },
{ url: "images/icons/icon-72x72.png", revision: '1' },
{ url: "images/maskable_icon.png", revision: '1' },
{ url: "favicon.ico", revision: '1' },
{ url: "pages/home.html", revision: '1' },
{ url: "pages/teams.html", revision: '1' },
{ url: "pages/saved.html", revision: '1' },
{ url: "https://fonts.googleapis.com/icon?family=Material+Icons", revision: '1' },
{ url: "https://fonts.gstatic.com/s/materialicons/v55/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2", revision: '1' }
], {
ignoreUrlParametersMatching: [/.*/]
});
workbox.routing.registerRoute(
new RegExp('https://api.football-data.org/'),
workbox.strategies.staleWhileRevalidate()
)
workbox.routing.registerRoute(
/.*(?:png|gif|jpg|jpeg|svg|ico)$/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'images',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200]
}),
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 hari
}),
],
}),
);
workbox.routing.registerRoute(
/.*(?:googleapis|gstatic)\.com/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'google-fonts-stylesheets',
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.staleWhileRevalidate({
cacheName: 'pages'
})
);
} else {
console.log(`Workbox berhasil dimuat`);
}
self.addEventListener('push', e => {
var body;
if (e.data) {
body = e.data.text();
} else {
body = 'Push message no payload';
}
const options = {
body: body,
icon: 'img/maskable_icon.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
}
};
e.waitUntil(
self.registration.showNotification('FootMatch Notification', options)
);
});