@cocreate/pwa 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/{src → demo}/css/global.css +0 -0
- package/{src → demo}/css/style.css +1 -1
- package/{src → demo}/css/test1.css +0 -0
- package/{src → demo}/css/test2.css +0 -0
- package/{src → demo}/css/test3.css +0 -0
- package/{src → demo}/images/icons/icon-128x128.png +0 -0
- package/{src → demo}/images/icons/icon-144x144.png +0 -0
- package/{src → demo}/images/icons/icon-152x152.png +0 -0
- package/{src → demo}/images/icons/icon-192x192.png +0 -0
- package/{src → demo}/images/icons/icon-256x256.png +0 -0
- package/{src → demo}/images/icons/icon-384x384.png +0 -0
- package/{src → demo}/images/icons/icon-512x512.png +0 -0
- package/{src → demo}/images/icons/icon-72x72.png +0 -0
- package/{src → demo}/images/icons/icon-96x96.png +0 -0
- package/{src → demo}/images/no-img.jpg +0 -0
- package/{src/test2.html → demo/index.html} +16 -18
- package/{src → demo}/js/test1.js +0 -0
- package/{src → demo}/js/test2.js +0 -0
- package/{src → demo}/js/test3.js +0 -0
- package/{src → demo}/manifest.json +0 -0
- package/{src → demo}/offline.html +0 -0
- package/{src → demo}/pages/test1.html +2 -11
- package/{src → demo}/pages/test2.html +2 -9
- package/{src → demo}/pages/test3.html +3 -8
- package/demo/sw.js +99 -0
- package/package.json +15 -6
- package/src/cache.js +44 -0
- package/src/{js/app.js → index.js} +30 -36
- package/webpack.config.js +6 -7
- package/.vscode/settings.json +0 -2
- package/src/.jshintrc +0 -75
- package/src/archive/index.test.html +0 -41
- package/src/archive/script.js +0 -102
- package/src/archive/service-worker.js +0 -37
- package/src/archive/style.css +0 -35
- package/src/archive/sw-basico.js +0 -38
- package/src/archive/sw-estrategias.js +0 -190
- package/src/index.html +0 -102
- package/src/pages/offline.html +0 -29
- package/src/sw.js +0 -95
- package/src/test1.html +0 -62
- package/src/test3.html +0 -60
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>Hello!</title>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
-
<!-- import the webpage's stylesheet -->
|
|
9
|
-
<link rel="stylesheet" href="style.css">
|
|
10
|
-
<!-- Manifest -->
|
|
11
|
-
<link rel="manifest" href="manifest.json">
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<h1>
|
|
15
|
-
InstallableR
|
|
16
|
-
</h1>
|
|
17
|
-
|
|
18
|
-
<p id="requireHTTPS" class="hidden">
|
|
19
|
-
<b>STOP!</b> This page <b>must</b> be served over HTTPS.
|
|
20
|
-
Please <a>reload this page via HTTPS</a>.
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
<p>
|
|
24
|
-
Make me installable, follow the
|
|
25
|
-
<a href="https://web.dev/codelab-make-installable/">instructions</a> here.
|
|
26
|
-
</p>
|
|
27
|
-
|
|
28
|
-
<!-- Install button, hidden by default -->
|
|
29
|
-
<div id="installContainer" class="hidden">
|
|
30
|
-
<button id="butInstall" type="button">
|
|
31
|
-
Install
|
|
32
|
-
</button>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<!-- import the webpage's javascript file -->
|
|
36
|
-
<script src="script.js" defer></script>
|
|
37
|
-
|
|
38
|
-
<!-- include the Glitch button to show what the webpage is about and
|
|
39
|
-
to make it easier for folks to view source and remix -->
|
|
40
|
-
</body>
|
|
41
|
-
</html>
|
package/src/archive/script.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
const divInstall = document.getElementById("installContainer");
|
|
2
|
-
const butInstall = document.getElementById("butInstall");
|
|
3
|
-
|
|
4
|
-
/* Put code here */
|
|
5
|
-
|
|
6
|
-
/* Only register a service worker if it's supported */
|
|
7
|
-
if ("serviceWorker" in navigator) {
|
|
8
|
-
navigator.serviceWorker
|
|
9
|
-
.register("./service-worker.js")
|
|
10
|
-
.register("./sw.js")
|
|
11
|
-
.then(function (registration) {
|
|
12
|
-
registration.addEventListener("updatefound", function () {
|
|
13
|
-
// If updatefound is fired, it means that there's
|
|
14
|
-
// a new service worker being installed.
|
|
15
|
-
var installingWorker = registration.installing;
|
|
16
|
-
console.log(
|
|
17
|
-
"A new service worker is being installed:",
|
|
18
|
-
installingWorker
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
// You can listen for changes to the installing service worker's
|
|
22
|
-
// state via installingWorker.onstatechange
|
|
23
|
-
});
|
|
24
|
-
})
|
|
25
|
-
.catch(function (error) {
|
|
26
|
-
console.log("Service worker registration failed:", error);
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
console.log("Service workers are not supported.");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Warn the page must be served over HTTPS
|
|
34
|
-
* The `beforeinstallprompt` event won't fire if the page is served over HTTP.
|
|
35
|
-
* Installability requires a service worker with a fetch event handler, and
|
|
36
|
-
* if the page isn't served over HTTPS, the service worker won't load.
|
|
37
|
-
*/
|
|
38
|
-
if (window.location.protocol === "http:") {
|
|
39
|
-
const requireHTTPS = document.getElementById("requireHTTPS");
|
|
40
|
-
const link = requireHTTPS.querySelector("a");
|
|
41
|
-
link.href = window.location.href.replace("http://", "https://");
|
|
42
|
-
requireHTTPS.classList.remove("hidden");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// "use strict";
|
|
46
|
-
|
|
47
|
-
// const fs = require("fs");
|
|
48
|
-
// const minimist = require("minimist");
|
|
49
|
-
// const glob = require("glob");
|
|
50
|
-
|
|
51
|
-
// const readArgv = () => {
|
|
52
|
-
// const argv = minimist(process.argv.slice(2));
|
|
53
|
-
// return {
|
|
54
|
-
// source: argv.source || "./dist/",
|
|
55
|
-
// dist: argv.dist || "./dist/service-worker.js",
|
|
56
|
-
// templatePath: argv.template || "./sw-template.js",
|
|
57
|
-
// cacheStore: argv.cache || "offline-files",
|
|
58
|
-
// navigationFallback: argv.navigationFallback || "index.html",
|
|
59
|
-
// };
|
|
60
|
-
// };
|
|
61
|
-
|
|
62
|
-
// const removeFile = (path) => {
|
|
63
|
-
// if (fs.existsSync(path)) {
|
|
64
|
-
// fs.unlinkSync(path);
|
|
65
|
-
// }
|
|
66
|
-
// };
|
|
67
|
-
|
|
68
|
-
// const isDirectory = (path) => {
|
|
69
|
-
// return fs.lstatSync(path).isDirectory();
|
|
70
|
-
// };
|
|
71
|
-
|
|
72
|
-
// const getFiles = (source) => {
|
|
73
|
-
// return glob
|
|
74
|
-
// .sync("**/*", { cwd: source })
|
|
75
|
-
// .filter((path) => !isDirectory(source + path));
|
|
76
|
-
// };
|
|
77
|
-
|
|
78
|
-
// const arrayToString = (array) => {
|
|
79
|
-
// const strings = array.map((item) => `'${item}'`).join(", ");
|
|
80
|
-
// return `[${strings}]`;
|
|
81
|
-
// };
|
|
82
|
-
|
|
83
|
-
// const generateSWFile = () => {
|
|
84
|
-
// const argv = readArgv();
|
|
85
|
-
// removeFile(argv.dist);
|
|
86
|
-
|
|
87
|
-
// const template = fs.readFileSync(argv.templatePath, "utf-8");
|
|
88
|
-
// const internalFiles = getFiles(argv.source);
|
|
89
|
-
// const externalFiles = [
|
|
90
|
-
// // here you can add some external files that you want to have cached
|
|
91
|
-
// ];
|
|
92
|
-
// const files = arrayToString([...internalFiles, ...externalFiles]);
|
|
93
|
-
// const content = [
|
|
94
|
-
// `const $CACHE_STORE = '${argv.cacheStore}';`,
|
|
95
|
-
// `const $NAVIGATION_FALLBACK = '${argv.navigationFallback}';\n`,
|
|
96
|
-
// `const $FILES = ${files};\n`,
|
|
97
|
-
// template,
|
|
98
|
-
// ].join("\n");
|
|
99
|
-
// fs.writeFileSync(argv.dist, content, "utf-8");
|
|
100
|
-
// };
|
|
101
|
-
|
|
102
|
-
// generateSWFile();
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
console.log("service worker start");
|
|
2
|
-
var CacheName = "TestPWA_Cache";
|
|
3
|
-
var CacheContents = [
|
|
4
|
-
"/",
|
|
5
|
-
"/index.html",
|
|
6
|
-
"/test1.html",
|
|
7
|
-
"/test2.html",
|
|
8
|
-
"/test3.html",
|
|
9
|
-
"style.css",
|
|
10
|
-
"/src/js/test1.js",
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
self.addEventListener("install", function (event) {
|
|
14
|
-
event.waitUntil(
|
|
15
|
-
caches
|
|
16
|
-
.open(CacheName)
|
|
17
|
-
.then(function (cache) {
|
|
18
|
-
console.log("Service worker install sucess.");
|
|
19
|
-
return cache.addAll(CacheContents).then(function () {
|
|
20
|
-
self.skipWaiting();
|
|
21
|
-
self.clients.claim();
|
|
22
|
-
});
|
|
23
|
-
})
|
|
24
|
-
.catch(function (err) {
|
|
25
|
-
console.log("Service worker install failed! " + err);
|
|
26
|
-
})
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
self.addEventListener("fetch", function (event) {
|
|
31
|
-
event.respondWith(
|
|
32
|
-
caches.match(event.request).then(function (response) {
|
|
33
|
-
if (response) return response;
|
|
34
|
-
return fetch(event.request);
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
});
|
package/src/archive/style.css
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
body {
|
|
2
|
-
background-color: #546e7a;
|
|
3
|
-
color: white;
|
|
4
|
-
font-family: Helvetica, Arial, sans-serif, "Apple Color Emoji",
|
|
5
|
-
"Segoe UI Emoji", "Segoe UI Symbol";
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
a,
|
|
9
|
-
a:visited {
|
|
10
|
-
color: white;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
h1 {
|
|
14
|
-
text-align: center;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.hidden {
|
|
18
|
-
display: none !important;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
#installContainer {
|
|
22
|
-
position: absolute;
|
|
23
|
-
bottom: 1em;
|
|
24
|
-
display: flex;
|
|
25
|
-
justify-content: center;
|
|
26
|
-
width: 100%;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#installContainer button {
|
|
30
|
-
background-color: inherit;
|
|
31
|
-
border: 1px solid white;
|
|
32
|
-
color: white;
|
|
33
|
-
font-size: 1em;
|
|
34
|
-
padding: 0.75em;
|
|
35
|
-
}
|
package/src/archive/sw-basico.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
self.addEventListener("fetch", (event) => {
|
|
2
|
-
const offlineResp = new Response(`
|
|
3
|
-
|
|
4
|
-
Welcome to my website
|
|
5
|
-
|
|
6
|
-
Sorry, but to use it, you need internet
|
|
7
|
-
|
|
8
|
-
`);
|
|
9
|
-
|
|
10
|
-
// const offlineResp = new Response(`
|
|
11
|
-
|
|
12
|
-
// <!DOCTYPE html>
|
|
13
|
-
// <html lang="en">
|
|
14
|
-
// <head>
|
|
15
|
-
// <meta charset="UTF-8">
|
|
16
|
-
// <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
17
|
-
// <meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
18
|
-
// <title>PWA Test</title>
|
|
19
|
-
|
|
20
|
-
// </head>
|
|
21
|
-
// <body class="container p-3">
|
|
22
|
-
|
|
23
|
-
// <h1>Offline Mode</h1>
|
|
24
|
-
|
|
25
|
-
// </body>
|
|
26
|
-
// </html>
|
|
27
|
-
// `, {
|
|
28
|
-
// headers: {
|
|
29
|
-
// 'Content-Type':'text/html'
|
|
30
|
-
// }
|
|
31
|
-
// });
|
|
32
|
-
|
|
33
|
-
// const offlineResp = fetch( 'pages/offline.html' );
|
|
34
|
-
|
|
35
|
-
const resp = fetch(event.request).catch(() => offlineResp);
|
|
36
|
-
|
|
37
|
-
event.respondWith(resp);
|
|
38
|
-
});
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// const CACHE_NAME = 'cache-1';
|
|
4
|
-
const CACHE_STATIC_NAME = 'static-v2';
|
|
5
|
-
const CACHE_DYNAMIC_NAME = 'dynamic-v1';
|
|
6
|
-
const CACHE_INMUTABLE_NAME = 'inmutable-v1';
|
|
7
|
-
|
|
8
|
-
const CACHE_DYNAMIC_LIMIT = 50;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function limpiarCache( cacheName, numeroItems ) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
caches.open( cacheName )
|
|
15
|
-
.then( cache => {
|
|
16
|
-
|
|
17
|
-
return cache.keys()
|
|
18
|
-
.then( keys => {
|
|
19
|
-
|
|
20
|
-
if ( keys.length > numeroItems ) {
|
|
21
|
-
cache.delete( keys[0] )
|
|
22
|
-
.then( limpiarCache(cacheName, numeroItems) );
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
self.addEventListener('install', e => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const cacheProm = caches.open( CACHE_STATIC_NAME )
|
|
37
|
-
.then( cache => {
|
|
38
|
-
|
|
39
|
-
return cache.addAll([
|
|
40
|
-
'/',
|
|
41
|
-
'/index.html',
|
|
42
|
-
'/css/style.css',
|
|
43
|
-
'/img/main.jpg',
|
|
44
|
-
'/js/app.js',
|
|
45
|
-
'/img/no-img.jpg'
|
|
46
|
-
]);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const cacheInmutable = caches.open( CACHE_INMUTABLE_NAME )
|
|
52
|
-
.then( cache => cache.add('https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css'));
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
e.waitUntil( Promise.all([cacheProm, cacheInmutable]) );
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
self.addEventListener('fetch', e =>{
|
|
62
|
-
|
|
63
|
-
// 5- Cache & Network Race
|
|
64
|
-
|
|
65
|
-
const respuesta = new Promise( (resolve, reject) =>{
|
|
66
|
-
|
|
67
|
-
let rechazada = false;
|
|
68
|
-
|
|
69
|
-
const falloUnaVez = () => {
|
|
70
|
-
|
|
71
|
-
if ( rechazada ) {
|
|
72
|
-
|
|
73
|
-
if ( /\.(png|jpg)$/i.test( e.request.url ) ) {
|
|
74
|
-
|
|
75
|
-
resolve( caches.match('/img/no-img.jpg') );
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
reject('No se encontro respuesta');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
rechazada = true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
fetch( e.request ).then( res => {
|
|
92
|
-
res.ok ? resolve(res) : falloUnaVez();
|
|
93
|
-
}).catch( falloUnaVez );
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
caches.match( e.request ).then( res => {
|
|
97
|
-
res ? resolve( res ) : falloUnaVez();
|
|
98
|
-
}).catch( falloUnaVez );
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
e.respondWith( respuesta );
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// 4- Cache with network update
|
|
110
|
-
// Rendimiento es crítico
|
|
111
|
-
// Siempre estarán un paso atrás
|
|
112
|
-
// if ( e.request.url.includes('bootstrap') ) {
|
|
113
|
-
// return e.respondWith( caches.match( e.request ) );
|
|
114
|
-
// }
|
|
115
|
-
|
|
116
|
-
// const respuesta = caches.open( CACHE_STATIC_NAME ).then( cache => {
|
|
117
|
-
|
|
118
|
-
// fetch( e.request ).then( newRes =>
|
|
119
|
-
// cache.put( e.request, newRes ));
|
|
120
|
-
|
|
121
|
-
// return cache.match( e.request );
|
|
122
|
-
|
|
123
|
-
// });
|
|
124
|
-
|
|
125
|
-
// e.respondWith( respuesta );
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// 3- Network with cache fallback
|
|
129
|
-
// const respuesta = fetch( e.request ).then( res => {
|
|
130
|
-
|
|
131
|
-
// if ( !res ) return caches.match( e.request );
|
|
132
|
-
|
|
133
|
-
// caches.open( CACHE_DYNAMIC_NAME )
|
|
134
|
-
// .then( cache => {
|
|
135
|
-
// cache.put( e.request, res );
|
|
136
|
-
// limpiarCache( CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT );
|
|
137
|
-
// });
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// return res.clone();
|
|
141
|
-
|
|
142
|
-
// }).catch( err =>{
|
|
143
|
-
// return caches.match( e.request );
|
|
144
|
-
// });
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// e.respondWith( respuesta );
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// 2- Cache with Network Fallback
|
|
152
|
-
// const respuesta = caches.match( e.request )
|
|
153
|
-
// .then( res => {
|
|
154
|
-
|
|
155
|
-
// if ( res ) return res;
|
|
156
|
-
|
|
157
|
-
// // No existe el archivo
|
|
158
|
-
// // tengo que ir a la web
|
|
159
|
-
// console.log('No existe', e.request.url );
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// return fetch( e.request ).then( newResp => {
|
|
163
|
-
|
|
164
|
-
// caches.open( CACHE_DYNAMIC_NAME )
|
|
165
|
-
// .then( cache => {
|
|
166
|
-
// cache.put( e.request, newResp );
|
|
167
|
-
// limpiarCache( CACHE_DYNAMIC_NAME, 50 );
|
|
168
|
-
// });
|
|
169
|
-
|
|
170
|
-
// return newResp.clone();
|
|
171
|
-
// });
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// });
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// e.respondWith( respuesta );
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// 1- Cache Only
|
|
183
|
-
// e.respondWith( caches.match( e.request ) );
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
package/src/index.html
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Hello!</title>
|
|
6
|
-
<meta charset="utf-8" />
|
|
7
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
|
-
<!-- import the webpage's stylesheet -->
|
|
10
|
-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
|
|
11
|
-
<link rel="stylesheet" href="./css/style.css" />
|
|
12
|
-
<!-- Manifest -->
|
|
13
|
-
<link rel="manifest" href="./manifest.json" />
|
|
14
|
-
<!--<link rel="manifest" href="./manifest.webmanifest"> -->
|
|
15
|
-
<!--<meta name="theme-color" content="red">-->
|
|
16
|
-
</head>
|
|
17
|
-
|
|
18
|
-
<body>
|
|
19
|
-
<h1>Installable</h1>
|
|
20
|
-
<nav class="navbar navbar-expand-sm bg-dark">
|
|
21
|
-
<!-- Links -->
|
|
22
|
-
<ul class="navbar-nav">
|
|
23
|
-
<li class="nav-item active">
|
|
24
|
-
<a class="nav-link" href="#">Home</a>
|
|
25
|
-
</li>
|
|
26
|
-
<li class="nav-item">
|
|
27
|
-
<a class="nav-link" href="./test1.html">Test1</a>
|
|
28
|
-
</li>
|
|
29
|
-
<li class="nav-item">
|
|
30
|
-
<a class="nav-link" href="./test2.html">Test 2</a>
|
|
31
|
-
</li>
|
|
32
|
-
<li class="nav-item">
|
|
33
|
-
<a class="nav-link" href="./test3.html">Test 3</a>
|
|
34
|
-
</li>
|
|
35
|
-
</ul>
|
|
36
|
-
</nav>
|
|
37
|
-
<p id="requireHTTPS" class="hidden">
|
|
38
|
-
<b>STOP!</b> This page <b>must</b> be served over HTTPS. Please
|
|
39
|
-
<a>reload this page via HTTPS</a>.
|
|
40
|
-
</p>
|
|
41
|
-
|
|
42
|
-
<p>
|
|
43
|
-
Make me installable, follow the
|
|
44
|
-
<a href="https://web.dev/codelab-make-installable/">instructions</a> here.
|
|
45
|
-
</p>
|
|
46
|
-
|
|
47
|
-
<button id="butCache">Uncache</button>
|
|
48
|
-
|
|
49
|
-
<!-- Install button, hidden by default -->
|
|
50
|
-
<div id="installContainer" class="hidden">
|
|
51
|
-
<button id="butInstall" type="button">Install</button>
|
|
52
|
-
</div>
|
|
53
|
-
|
|
54
|
-
<!-- include the Glitch button to show what the webpage is about and
|
|
55
|
-
to make it easier for folks to view source and remix -->
|
|
56
|
-
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
|
|
57
|
-
<script src="https://button.glitch.me/button.js"></script>
|
|
58
|
-
<!-- import the webpage's javascript file -->
|
|
59
|
-
<script src="./js/app.js" defer></script>
|
|
60
|
-
<script>
|
|
61
|
-
window.isUpdateAvailable = new Promise(function(resolve, reject) {
|
|
62
|
-
// lazy way of disabling service workers while developing
|
|
63
|
-
if ('serviceWorker' in navigator) {
|
|
64
|
-
// register service worker file
|
|
65
|
-
navigator.serviceWorker.register('sw.js')
|
|
66
|
-
.then(reg => {
|
|
67
|
-
reg.onupdatefound = () => {
|
|
68
|
-
const installingWorker = reg.installing;
|
|
69
|
-
installingWorker.onstatechange = () => {
|
|
70
|
-
console.log(installingWorker.state);
|
|
71
|
-
switch (installingWorker.state) {
|
|
72
|
-
case 'installed':
|
|
73
|
-
if (navigator.serviceWorker.controller) {
|
|
74
|
-
// new update available
|
|
75
|
-
resolve(true);
|
|
76
|
-
} else {
|
|
77
|
-
// no update available
|
|
78
|
-
resolve(false);
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
})
|
|
85
|
-
.catch(err => console.error('[SW ERROR]', err));
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
document.addEventListener("DOMContentLoaded", function(event) {
|
|
90
|
-
window['isUpdateAvailable']
|
|
91
|
-
.then(isAvailable => {
|
|
92
|
-
if (isAvailable) {
|
|
93
|
-
alert('xxxxxxxxxxxxxxx');
|
|
94
|
-
} else {
|
|
95
|
-
alert('yyyyyyyyyyyyyyy');
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
</script>
|
|
100
|
-
</body>
|
|
101
|
-
|
|
102
|
-
</html>
|