-
Notifications
You must be signed in to change notification settings - Fork 830
/
Copy pathindex.html
93 lines (82 loc) · 2.61 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>workbox-window demo</title>
<meta
name="workbox-window demo"
content="An example to demonstrate the workbox-window module"
/>
<link
id="favicon"
rel="icon"
href="https://glitch.com/edit/favicon-app.ico"
type="image/x-icon"
/>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
margin-left: 5%;
font-family: 'Open Sans', sans-serif;
}
ol {
padding-left: 20px;
}
li {
margin-bottom: 5px;
}
button {
margin: 20px 0;
font-weight: bold;
}
</style>
</head>
<body>
<header>
<div>
<h1>workbox-window Demo</h1>
</div>
</header>
<ol>
<li>workbox-window runs in the window context, not the service worker</li>
<li>Open up DevTools and go to the console</li>
</ol>
<script type="module">
import {Workbox} from 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0-beta.1/workbox-window.prod.mjs';
if ('serviceWorker' in navigator) {
const wb = new Workbox('/sw.js');
wb.addEventListener('activated', (event) => {
// `event.isUpdate` will be true if another version of the service
// worker was controlling the page when this version was registered.
if (!event.isUpdate) {
console.log('Service worker activated for the first time!');
// If your service worker is configured to precache assets, those
// assets should all be available now.
}
});
wb.addEventListener('waiting', (event) => {
console.log(
`A new service worker has installed, but it can't activate` +
`until all tabs running the current version have fully unloaded.`,
);
});
// Register the service worker after event listeners have been added.
wb.register();
const message = async () => {
const swVersion = await wb.messageSW({type: 'GET_VERSION'});
console.log('Service Worker version:', swVersion);
};
message();
}
</script>
<a href="https://developers.google.com/web/tools/workbox/modules"
>Back to Demos</a
>
<p>
<a href="https://developers.google.com/web/tools/workbox">Docs</a> |
<a href="https://github.com/googlechrome/workbox">GitHub</a> |
<a href="https://twitter.com/workboxjs">@workboxjs</a>
</p>
</body>
</html>