-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.js
33 lines (30 loc) · 1.02 KB
/
index.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
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js', {
// The Service-Worker-Allowed must be set to '/'
scope: '/',
// Allow the service worker to use modules
type: 'module',
// Don't cache http requests.
updateViaCache: 'none'
}).then(reg => {
// Update service worker
reg.update();
// When the service worker is ready.
if ('active' in reg) {
// Share server data with the service worker.
const chan = new MessageChannel();
reg.active.postMessage(ctx, [chan.port2]);
// Reload page
location.reload();
} else
console.log(reg.state);
});
} else {
const firefox = false;
// Service workers can't be created if on private browsing mode on firefox
if (firefox) {
document.write('❌ Please leave private browsing mode.');
} else {
document.write('❌ Service workers are not supported!');
}
}