@cocreate/pwa 1.6.10 → 1.6.12

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.
@@ -1,56 +1,56 @@
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
10
- rel="stylesheet"
11
- href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
12
- <link rel="stylesheet" href="../css/style.css" />
13
- <link rel="stylesheet" href="../css/test3.css" />
14
- <!-- Manifest -->
15
- <link rel="manifest" href="../manifest.webmanifest" />
16
- <!--<link rel="manifest" href="./manifest.webmanifest"> -->
17
- <link rel="manifest" href="/manifest.webmanifest" />
18
- </head>
19
-
20
- <body class="test3-bg-color">
21
- <nav class="navbar navbar-expand-sm bg-dark">
22
- <!-- Links -->
23
- <ul class="navbar-nav">
24
- <li class="nav-item active">
25
- <a class="nav-link" href="../index.html">Home</a>
26
- </li>
27
- <li class="nav-item">
28
- <a class="nav-link" href="./test1.html">Test1</a>
29
- </li>
30
- <li class="nav-item">
31
- <a class="nav-link" href="./test2.html">Test 2</a>
32
- </li>
33
- <li class="nav-item">
34
- <a class="nav-link" href="#">Test 3</a>
35
- </li>
36
- </ul>
37
- </nav>
38
- <p id="requireHTTPS" class="hidden">
39
- <b>STOP!</b> This page <b>must</b> be served over HTTPS. Please
40
- <a>reload this page via HTTPS</a>.
41
- </p>
42
-
43
- <p>
44
- Make me installable, follow the
45
- <a href="https://web.dev/codelab-make-installable/">instructions</a>
46
- here.
47
- </p>
48
-
49
- <!-- Install button, hidden by default -->
50
- <div id="installContainer" class="hidden">
51
- <button id="installBtn" type="button">Install</button>
52
- </div>
53
-
54
- <script src="../../dist/CoCreate-pwa.js" defer></script>
55
- </body>
56
- </html>
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
10
+ rel="stylesheet"
11
+ href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
12
+ <link rel="stylesheet" href="../css/style.css" />
13
+ <link rel="stylesheet" href="../css/test3.css" />
14
+ <!-- Manifest -->
15
+ <link rel="manifest" href="../manifest.webmanifest" />
16
+ <!--<link rel="manifest" href="./manifest.webmanifest"> -->
17
+ <link rel="manifest" href="/manifest.webmanifest" />
18
+ </head>
19
+
20
+ <body class="test3-bg-color">
21
+ <nav class="navbar navbar-expand-sm bg-dark">
22
+ <!-- Links -->
23
+ <ul class="navbar-nav">
24
+ <li class="nav-item active">
25
+ <a class="nav-link" href="../index.html">Home</a>
26
+ </li>
27
+ <li class="nav-item">
28
+ <a class="nav-link" href="./test1.html">Test1</a>
29
+ </li>
30
+ <li class="nav-item">
31
+ <a class="nav-link" href="./test2.html">Test 2</a>
32
+ </li>
33
+ <li class="nav-item">
34
+ <a class="nav-link" href="#">Test 3</a>
35
+ </li>
36
+ </ul>
37
+ </nav>
38
+ <p id="requireHTTPS" class="hidden">
39
+ <b>STOP!</b> This page <b>must</b> be served over HTTPS. Please
40
+ <a>reload this page via HTTPS</a>.
41
+ </p>
42
+
43
+ <p>
44
+ Make me installable, follow the
45
+ <a href="https://web.dev/codelab-make-installable/">instructions</a>
46
+ here.
47
+ </p>
48
+
49
+ <!-- Install button, hidden by default -->
50
+ <div id="installContainer" class="hidden">
51
+ <button id="installBtn" type="button">Install</button>
52
+ </div>
53
+
54
+ <script src="../../dist/CoCreate-pwa.js" defer></script>
55
+ </body>
56
+ </html>
package/demo/sw.js CHANGED
@@ -1,112 +1,112 @@
1
- const CACHE_STATIC_NAME = "static-v1";
2
- const CACHE_DYNAMIC_NAME = "dynamic-v2";
3
- const CACHE_INMUTABLE_NAME = "inmutable-v1";
4
- const CACHE_TEMP = 'temp-cache';
5
- const CACHE_DYNAMIC_LIMIT = 50;
6
- const fetchedMap = []
7
- const cacheType = 'cache'
8
- const requestMap = new Map()
9
-
10
- function deleteCache(key) {
11
- return caches.delete(key);
12
- }
13
-
14
- self.addEventListener("install", (e) => {
15
- console.log('Service Worker Installing')
16
-
17
- self.skipWaiting();
18
- // caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
19
- // cache.keys().then((keys) => {
20
- // keys.forEach(key => {
21
- // fetchedMap.push(key.url)
22
- // })
23
- // deleteCache()
24
- // })
25
- // })
26
- });
27
-
28
- self.addEventListener("activate", async (e) => {
29
- // console.log('sw activate Event!')
30
- // const bgFetch = await self.registration.backgroundFetch.fetch(new Date().toISOString(), fetchedMap);
31
- // console.log('backgfetch', bgFetch)
32
-
33
- // e.waitUntil(updateCache())
34
- // updateCache()
35
- e.waitUntil(clients.claim());
36
- });
37
-
38
- self.addEventListener("fetch", (e) => {
39
- if (!(e.request.url.indexOf('http') === 0)) return;
40
- e.respondWith(
41
- caches
42
- .match(e.request)
43
- .then((cachesObj) => {
44
- if (!navigator.onLine && !!cachesObj)
45
- return cachesObj;
46
-
47
- if (cacheType == 'cache' && !!cachesObj) {
48
- // console.log('returned from cache')
49
- requestMap.set(cachesObj, '')
50
- fetch(e.request).then((newResp) => {
51
- caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
52
- cache.put(e.request, newResp);
53
- // cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
54
- }).catch(() => {
55
-
56
- });
57
- }).catch(() => {
58
- return caches.match('./offline.html');
59
- })
60
- return cachesObj;
61
- } else {
62
- return fetch(e.request).then((newResp) => {
63
- caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
64
- cache.put(e.request, newResp);
65
- // cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
66
- }).catch(() => {});
67
- return newResp.clone();
68
- })
69
- .catch(() => {
70
- return caches.match('./offline.html');
71
- })
72
- }
73
- })
74
- .catch(function() {
75
- console.log('Fetch failed retuned offline page! ')
76
- return caches.match('./offline.html');
77
- })
78
- );
79
- });
80
-
81
- async function updateCache(){
82
- console.log('updateCache!')
83
- caches.open(CACHE_DYNAMIC_NAME)
84
- .then((cache) => {
85
- console.log('added', fetchedMap)
86
- cache.addAll(fetchedMap)
87
- }
88
- )
89
- }
90
-
91
- self.addEventListener('backgroundfetchsuccess', (event) => {
92
- const bgFetch = event.registration;
93
-
94
- event.waitUntil(async function() {
95
- // Create/open a cache.
96
- const cache = await caches.open(CACHE_DYNAMIC_NAME);
97
- // Get all the records.
98
- const records = await bgFetch.matchAll();
99
- // Copy each request/response across.
100
- const promises = records.map(async (record) => {
101
- const response = await record.responseReady;
102
- console.log('putting ')
103
- await cache.put(record.request, response);
104
- });
105
-
106
- // Wait for the copying to complete
107
- await Promise.all(promises);
108
-
109
- // Update the progress notification.
110
- // event.updateUI({ title: 'Episode 5 ready to listen!' });
111
- }());
1
+ const CACHE_STATIC_NAME = "static-v1";
2
+ const CACHE_DYNAMIC_NAME = "dynamic-v2";
3
+ const CACHE_INMUTABLE_NAME = "inmutable-v1";
4
+ const CACHE_TEMP = 'temp-cache';
5
+ const CACHE_DYNAMIC_LIMIT = 50;
6
+ const fetchedMap = []
7
+ const cacheType = 'cache'
8
+ const requestMap = new Map()
9
+
10
+ function deleteCache(key) {
11
+ return caches.delete(key);
12
+ }
13
+
14
+ self.addEventListener("install", (e) => {
15
+ console.log('Service Worker Installing')
16
+
17
+ self.skipWaiting();
18
+ // caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
19
+ // cache.keys().then((keys) => {
20
+ // keys.forEach(key => {
21
+ // fetchedMap.push(key.url)
22
+ // })
23
+ // deleteCache()
24
+ // })
25
+ // })
26
+ });
27
+
28
+ self.addEventListener("activate", async (e) => {
29
+ // console.log('sw activate Event!')
30
+ // const bgFetch = await self.registration.backgroundFetch.fetch(new Date().toISOString(), fetchedMap);
31
+ // console.log('backgfetch', bgFetch)
32
+
33
+ // e.waitUntil(updateCache())
34
+ // updateCache()
35
+ e.waitUntil(clients.claim());
36
+ });
37
+
38
+ self.addEventListener("fetch", (e) => {
39
+ if (!(e.request.url.indexOf('http') === 0)) return;
40
+ e.respondWith(
41
+ caches
42
+ .match(e.request)
43
+ .then((cachesObj) => {
44
+ if (!navigator.onLine && !!cachesObj)
45
+ return cachesObj;
46
+
47
+ if (cacheType == 'cache' && !!cachesObj) {
48
+ // console.log('returned from cache')
49
+ requestMap.set(cachesObj, '')
50
+ fetch(e.request).then((newResp) => {
51
+ caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
52
+ cache.put(e.request, newResp);
53
+ // cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
54
+ }).catch(() => {
55
+
56
+ });
57
+ }).catch(() => {
58
+ return caches.match('./offline.html');
59
+ })
60
+ return cachesObj;
61
+ } else {
62
+ return fetch(e.request).then((newResp) => {
63
+ caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
64
+ cache.put(e.request, newResp);
65
+ // cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
66
+ }).catch(() => {});
67
+ return newResp.clone();
68
+ })
69
+ .catch(() => {
70
+ return caches.match('./offline.html');
71
+ })
72
+ }
73
+ })
74
+ .catch(function() {
75
+ console.log('Fetch failed retuned offline page! ')
76
+ return caches.match('./offline.html');
77
+ })
78
+ );
79
+ });
80
+
81
+ async function updateCache(){
82
+ console.log('updateCache!')
83
+ caches.open(CACHE_DYNAMIC_NAME)
84
+ .then((cache) => {
85
+ console.log('added', fetchedMap)
86
+ cache.addAll(fetchedMap)
87
+ }
88
+ )
89
+ }
90
+
91
+ self.addEventListener('backgroundfetchsuccess', (event) => {
92
+ const bgFetch = event.registration;
93
+
94
+ event.waitUntil(async function() {
95
+ // Create/open a cache.
96
+ const cache = await caches.open(CACHE_DYNAMIC_NAME);
97
+ // Get all the records.
98
+ const records = await bgFetch.matchAll();
99
+ // Copy each request/response across.
100
+ const promises = records.map(async (record) => {
101
+ const response = await record.responseReady;
102
+ console.log('putting ')
103
+ await cache.put(record.request, response);
104
+ });
105
+
106
+ // Wait for the copying to complete
107
+ await Promise.all(promises);
108
+
109
+ // Update the progress notification.
110
+ // event.updateUI({ title: 'Episode 5 ready to listen!' });
111
+ }());
112
112
  });