-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
94 lines (86 loc) · 2.31 KB
/
sw.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
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'
);
if (workbox) {
console.log('Workbox berhasil dimuat');
} else {
console.log('Workbox gagal dimuat');
}
workbox.precaching.precacheAndRoute(
[
{ url: '/index.html', revision: '2' },
{ url: '/pages/pl.html', revision: '2' },
{ url: '/pages/list.html', revision: '2' },
{ url: '/css/materialize.min.css', revision: '2' },
{ url: '/js/materialize.min.js', revision: '2' },
{ url: '/css/about.css', revision: '2' },
{ url: '/css/list.css', revision: '2' },
{ url: '/css/pl.css', revision: '2' },
{ url: '/css/ucl.css', revision: '2' },
{ url: '/js/api.js', revision: '2' },
{ url: '/js/db.js', revision: '2' },
{ url: '/js/getdata.js', revision: '2' },
{ url: '/js/idb.js', revision: '2' },
{ url: '/js/registersw.js', revision: '2' },
{ url: '/js/setup.js', revision: '2' },
{ url: '/pages/about.html', revision: '2' },
{ url: '/manifest.json', revision: '2' },
],
{
// Ignore all URL parameters.
ignoreURLParametersMatching: [/.*/],
}
);
workbox.routing.registerRoute(
new RegExp('/pages/about.html'),
new workbox.strategies.CacheFirst()
);
workbox.routing.registerRoute(
/^https:\/\/fonts\.googleapis\.com/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'Google-fonts-stylesheets',
})
);
workbox.routing.registerRoute(
/^https:\/\/api\.football\-data\.org\/v2\//,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'API Request',
})
);
workbox.routing.registerRoute(
/^https:\/\/crests\.football\-data\.org\/(\w+)\.(svg|png|jpg|gif|vector|bitmap|JPEG)/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'API Images Request',
plugins: [
new workbox.expiration.ExpirationPlugin({
maxEntries: 25,
}),
],
})
);
workbox.routing.registerRoute(
/^([\/pages\/pl\.html|\/index.html|\/pages\/list\.html])/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'Pages',
})
);
self.addEventListener('push', function (event) {
let body;
if (event.data) {
body = event.data.text();
} else {
body = 'Push message no payload';
}
let options = {
body: body,
icon: '/img/72.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1,
},
};
event.waitUntil(
self.registration.showNotification('Push Notification', options)
);
});