@cocreate/pwa 1.19.0 → 1.19.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.19.1](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.19.0...v1.19.1) (2024-04-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * uncommented checkCache ([7372303](https://github.com/CoCreate-app/CoCreate-pwa/commit/737230325c59346687b699b3dfc0496be038f5a6))
7
+
1
8
  # [1.19.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.18.2...v1.19.0) (2024-03-18)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/pwa",
3
- "version": "1.19.0",
3
+ "version": "1.19.1",
4
4
  "description": "A simple pwa component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "pwa",
@@ -23,6 +23,8 @@
23
23
  */
24
24
 
25
25
  const cacheName = "dynamic-v2";
26
+ const updatedOn = new Date('2024-04-28T03:15:28.668Z');
27
+
26
28
  let organization_id = ""
27
29
  let storage = true
28
30
 
@@ -46,14 +48,23 @@ self.addEventListener("fetch", async (e) => {
46
48
  caches
47
49
  .match(e.request)
48
50
  .then(async (cacheResponse) => {
49
- if (!navigator.onLine || !!cacheResponse && cacheType !== 'false') {
50
- const organization = cacheResponse.headers.get('organization')
51
- const lastModified = cacheResponse.headers.get('last-modified')
51
+ let fetchedOn
52
+ if (cacheResponse && cacheType !== 'false') {
53
+ fetchedOn = cacheResponse.headers.get('fetched-on')
54
+ if (fetchedOn)
55
+ fetchedOn = new Date(fetchedOn)
56
+ }
52
57
 
53
- // returnedFromCache[e.request.url] = { organization, lastModified }
58
+ const organization = cacheResponse.headers.get('organization')
59
+
60
+ if (!navigator.onLine || !!cacheResponse && cacheType !== 'false' && (!fetchedOn && !organization || fetchedOn > updatedOn)) {
61
+ console.log('servering cache fetchOn greater', fetchedOn > updatedOn, organization)
62
+ const lastModified = cacheResponse.headers.get('last-modified')
54
63
  sendCacheUpdate(e.request.url, organization, lastModified);
55
64
  return cacheResponse;
56
65
  } else {
66
+ console.log('fetching fetchOn less', fetchedOn > updatedOn)
67
+
57
68
  const networkResponse = await fetch(e.request);
58
69
 
59
70
  if (!organization_id)
@@ -178,7 +189,7 @@ const sendCacheUpdate = (url, organization, lastModified) => {
178
189
  });
179
190
 
180
191
  fetchTimeout = null;
181
- returnedFromCache = {};
192
+ // returnedFromCache = {};
182
193
  }, 500);
183
194
  };
184
195