-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
111 lines (101 loc) · 4.53 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<link rel="manifest" href="manifest.webmanifest">
<link rel="apple-touch-icon" href="demo_app/src/assets/square.png">
<meta name="apple-mobile-web-app-status-bar" content="#000000">
<meta name="theme-color" content="#000000">
<link rel=stylesheet href="demo_app/dist/app.css"></link>
<style>
</style>
<script>
// Check that service workers are supported
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
function registerSW() {
navigator.serviceWorker
.register('./demo_app/sw.js')
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated pre-cached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
caches.keys().then(function(names) {
for (let name of names)
caches.delete(name);
});
} else {
// At this point, everything has been pre-cached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
if ("serviceWorker" in navigator) addEventListener('load', () => {
if(isLocalhost) {
// Add some additional logging to localhost, pointing developers to the
// Check if the service worker can be found. If it can't reload the page.
fetch('./demoapp/sw.js')
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerSW();
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log('This web app is being served cache-first by a service worker.');
});
}
else {
registerSW();
}
});
</script>
<script src="./demo_app/dist/app.js" type="module"> </script>
</head>
<body style="background-color:#101010;">
</body>
</html>