parent
48292232b9
commit
5c1f449f67
@ -0,0 +1 @@ |
|||||||
|
test |
@ -0,0 +1,22 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
testing PWA |
||||||
|
|
||||||
|
doesnt have to have a manifest as this is only for the home screen |
||||||
|
|
||||||
|
surely works on iOS as my own IterativeExploration page is there |
||||||
|
(somehow added to HomeScreen, yet nothing related found |
||||||
|
cf serverhome/web/iterative-explorations.com/www/index.html ) |
||||||
|
<script> |
||||||
|
if ('serviceWorker' in navigator) { |
||||||
|
window.addEventListener('load', () => { |
||||||
|
// does not work on Firefox, use https rather than http |
||||||
|
navigator.serviceWorker |
||||||
|
.register('sw.js') |
||||||
|
.then(reg => console.log('Service Worker: Registered (Pages)')) |
||||||
|
.catch(err => console.log(`Service Worker: Error: ${err}`)); |
||||||
|
}); |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
</html> |
@ -0,0 +1,44 @@ |
|||||||
|
const cacheAssets = [ |
||||||
|
'/pwa/index.html', |
||||||
|
'/pwa/testdata.json', |
||||||
|
] |
||||||
|
const cacheName = '00004'; |
||||||
|
|
||||||
|
// Call Install Event
|
||||||
|
self.addEventListener('install', e => { |
||||||
|
console.log('Service Worker: Installed'); |
||||||
|
|
||||||
|
e.waitUntil( |
||||||
|
async () => { |
||||||
|
cache = await caches.open(cacheName); |
||||||
|
console.log('Service Worker: Caching Files', cache); |
||||||
|
await cache.addAll(cacheAssets); |
||||||
|
self.skipWaiting(); |
||||||
|
} |
||||||
|
); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
// Call Activate Event
|
||||||
|
self.addEventListener('activate', e => { |
||||||
|
console.log('Service Worker: Activated'); |
||||||
|
// Remove unwanted caches
|
||||||
|
e.waitUntil( |
||||||
|
caches.keys().then(cacheNames => { |
||||||
|
return Promise.all( |
||||||
|
cacheNames.map(cache => { |
||||||
|
if (cache !== cacheName) { |
||||||
|
console.log('Service Worker: Clearing Old Cache'); |
||||||
|
return caches.delete(cache); |
||||||
|
} |
||||||
|
}) |
||||||
|
); |
||||||
|
}) |
||||||
|
); |
||||||
|
}); |
||||||
|
|
||||||
|
// Call Fetch Event
|
||||||
|
self.addEventListener('fetch', e => { |
||||||
|
console.log('Service Worker: Fetching'); |
||||||
|
e.respondWith(fetch(e.request).catch(() => caches.match(e.request))); |
||||||
|
}); |
Loading…
Reference in new issue