-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
124 lines (111 loc) · 3.29 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
117
118
119
120
121
122
123
124
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js')
const pesanConsoleBerhasil = () => console.log(`Workbox berhasil dimuat`);
const pesanConsoleGagal = () => console.log(`Workbox gagal dimuat`);
workbox ? pesanConsoleBerhasil() : pesanConsoleGagal();
workbox.precaching.precacheAndRoute([
{ url:'/', revision: '1' },
{ url:'/index.html', revision: '1' },
{ url:'/manifest.json', revision: '1' },
{ url:'/push.js', revision: '1' },
{ url:'/service-worker.js', revision: '1' },
{ url:'/css/icons.css', revision: '1' },
{ url:'/css/materialize.css', revision: '1' },
{ url:'/css/style.css', revision: '1' },
{ url:'/font/MaterialIcons-Regular.ttf', revision: '1' },
{ url:'/pages/fav-team.html', revision: '1' },
{ url:'/pages/home.html', revision: '1' },
{ url:'/pages/match.html', revision: '1' },
{ url:'/pages/team.html', revision: '1' },
{ url:'/pages/nav.html', revision: '1' },
{ url:'/js/api.js', revision: '1' },
{ url:'/js/db.js', revision: '1' },
{ url:'/js/functions.js', revision: '1' },
{ url:'/js/idb.js', revision: '1' },
{ url:'/js/init.js', revision: '1' },
{ url:'/js/materialize.js', revision: '1' },
{ url:'/js/script.js', revision: '1' },
{ url:'/img/android-72x72.png', revision: '1' },
{ url:'/img/apple-icon-180x180.png', revision: '1' },
{ url:'/img/icon192x192.png', revision: '1' },
{ url:'/img/icon512x512.png', revision: '1' },
{ url:'/img/laliga.png', revision: '1' }
])
workbox.routing.registerRoute(
new RegExp("js/"),
workbox.strategies.staleWhileRevalidate({
cacheName: "js",
})
);
workbox.routing.registerRoute(
new RegExp("css/"),
workbox.strategies.staleWhileRevalidate({
cacheName: "css",
})
);
workbox.routing.registerRoute(
new RegExp("pages/"),
workbox.strategies.staleWhileRevalidate({
cacheName: "pages",
})
);
workbox.routing.registerRoute(
new RegExp("img/"),
workbox.strategies.staleWhileRevalidate({
cacheName: "img",
})
);
workbox.routing.registerRoute(
new RegExp("font/"),
workbox.strategies.cacheFirst({
cacheName: "img",
})
);
workbox.routing.registerRoute(
new RegExp("/"),
workbox.strategies.staleWhileRevalidate({
cacheName: "depan",
})
);
workbox.routing.registerRoute(
/^https:\/\/api\.football-data\.org\/v2/,
workbox.strategies.staleWhileRevalidate({
cacheName: "https://api.football-data.org/",
})
);
workbox.routing.registerRoute(
/.*(?:png|gif|jpg|jpeg|svg)$/,
workbox.strategies.cacheFirst({
cacheName: 'images',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200]
}),
new workbox.expiration.Plugin({
maxEntries: 100,
maxAgeSeconds: 30 * 24 * 60 * 60,
}),
]
})
);
// * push notification
self.addEventListener('push', event => {
console.log(event);
let body;
if (event.data) {
body = event.data.text()
}else{
body = "push message no payload"
}
let opt ={
body,
icon : './img/pwa-512x512.png',
vibrate : [100,50,100],
data : {
dateOfArrival : Date.now(),
primaryKey : 1
}
}
event.waitUntil(
self.registration.showNotification('Push notification',opt)
)
})