-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsw.js
More file actions
80 lines (69 loc) · 2.01 KB
/
sw.js
File metadata and controls
80 lines (69 loc) · 2.01 KB
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
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js');
var urlsToCache = [
{ url: '/', revision: '1' },
{ url: '/img/ball.png', revision: '1' },
{ url: '/img/empty_badge.svg', revision: '1' },
{ url: '/css/main.css', revision: '1' },
{ url: '/js/main.js', revision: '1' },
{ url: '/js/nav.js', revision: '1' },
{ url: '/js/api.js', revision: '1' },
{ url: '/js/idb.js', revision: '1' },
{ url: '/nav.html', revision: '1' },
{ url: '/index.html', revision: '1' },
{ url: '/materialize/css/materialize.min.css', revision: '1' },
{ url: '/materialize/js/materialize.min.js', revision: '1' },
]
if(workbox){
// Force development builds
//workbox.setConfig({ debug: true });
// The most verbose - displays all logs.
//workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug);
workbox.precaching.precacheAndRoute(urlsToCache);
workbox.routing.registerRoute(
/.*(?:png|gif|jpg|jpeg|svg)$/,
workbox.strategies.cacheFirst({
cacheName: 'images-cache',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200]
}),
new workbox.expiration.Plugin({
maxEntries: 100,
maxAgeSeconds: 30 * 24 * 60 * 60,
}),
]
})
);
workbox.routing.registerRoute(
new RegExp('https://api.football-data.org/v2/'),
workbox.strategies.staleWhileRevalidate()
)
// Caching Google Fonts
workbox.routing.registerRoute(
/.*(?:googleapis|gstatic)\.com/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'google-fonts-stylesheets',
})
);
}
self.addEventListener('push', event => {
var body;
console.log(event);
if(event.data) {
body = event.data.text()
} else {
body = "This is push message"
}
var options = {
body: body,
icon: '/img/ball.png',
vibrate: [500, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
}
}
event.waitUntil(
self.registration.showNotification('Push Notification', options)
);
});