Initial proof of concept
This commit is contained in:
parent
b80602e230
commit
85e9e1f5f1
8 changed files with 101 additions and 0 deletions
33
sw.js
Normal file
33
sw.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const CACHE_NAME = 'lips-pwa';
|
||||
const urlsToCache = ['/',
|
||||
'/index.html',
|
||||
'/app.scm',
|
||||
'/manifest.json',
|
||||
'https://cdn.jsdelivr.net/npm/lips@beta/dist/lips.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/mithril/2.2.2/mithril.min.js'];
|
||||
|
||||
// Install event: cache the assets
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(cache => {
|
||||
console.log('Opened cache');
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Fetch event: serve cached assets when offline
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => {
|
||||
// Cache hit - return the response
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
// Otherwise, fetch from network
|
||||
return fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue