|
|
|
|
|
|
|
|
'/message.html', |
|
|
'/message.html', |
|
|
'/bookmark.js', |
|
|
'/bookmark.js', |
|
|
'/createMessage.js', |
|
|
'/createMessage.js', |
|
|
'/files', |
|
|
|
|
|
|
|
|
'/files.js', |
|
|
'/home.js', |
|
|
'/home.js', |
|
|
'/main.js', |
|
|
'/main.js', |
|
|
'/profil.js', |
|
|
'/profil.js', |
|
|
'/img/favicon.ico', |
|
|
|
|
|
|
|
|
'/favicon.ico', |
|
|
'/img/th_nbg_ohmicon_amp.png', |
|
|
'/img/th_nbg_ohmicon_amp.png', |
|
|
'/lib/jquery-3.3.1.min.js', |
|
|
'/lib/jquery-3.3.1.min.js', |
|
|
'/lib/vue.js', |
|
|
'/lib/vue.js', |
|
|
|
|
|
|
|
|
]; |
|
|
]; |
|
|
const logicFilesToCache = [ |
|
|
const logicFilesToCache = [ |
|
|
'', |
|
|
'', |
|
|
'', |
|
|
|
|
|
]; |
|
|
]; |
|
|
const dataFilesToCache = [ |
|
|
const dataFilesToCache = [ |
|
|
'', |
|
|
'', |
|
|
'', |
|
|
|
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
// NOTE: Registration done in main.js |
|
|
// NOTE: Registration done in main.js |
|
|
|
|
|
|
|
|
caches.open(shellCacheKey).then(function (cache) { |
|
|
caches.open(shellCacheKey).then(function (cache) { |
|
|
console.log('[ServiceWorker] Cache shell files.'); |
|
|
console.log('[ServiceWorker] Cache shell files.'); |
|
|
return cache.addAll(shellFilesToCache); |
|
|
return cache.addAll(shellFilesToCache); |
|
|
}), |
|
|
|
|
|
|
|
|
}).then(self.skipWaiting()), |
|
|
caches.open(logicCasheKey).then(function (cache) { |
|
|
caches.open(logicCasheKey).then(function (cache) { |
|
|
console.log('[ServiceWorker] Cache logic files.'); |
|
|
console.log('[ServiceWorker] Cache logic files.'); |
|
|
return cache.addAll(logicFilesToCache); |
|
|
return cache.addAll(logicFilesToCache); |
|
|
}), |
|
|
|
|
|
|
|
|
}).then(self.skipWaiting()), |
|
|
caches.open(dataCacheKey).then(function (cache) { |
|
|
caches.open(dataCacheKey).then(function (cache) { |
|
|
console.log('[ServiceWorker] Cache data files.'); |
|
|
console.log('[ServiceWorker] Cache data files.'); |
|
|
return cache.addAll(dataFilesToCache); |
|
|
return cache.addAll(dataFilesToCache); |
|
|
}) |
|
|
|
|
|
|
|
|
}).then(self.skipWaiting()) |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// NOTE: Activate structure and delete older cache versions |
|
|
// NOTE: Activate structure and delete older cache versions |
|
|
self.addEventListener('activate', function (event) { |
|
|
self.addEventListener('activate', function (event) { |
|
|
console.log('[ServiceWorker] Activate'); |
|
|
console.log('[ServiceWorker] Activate'); |
|
|
/*const cacheWhitelist = [staticCacheName]; |
|
|
|
|
|
event.waitUntil( |
|
|
|
|
|
caches.keys().then(function (cacheNames) { |
|
|
|
|
|
return Promise.all( |
|
|
|
|
|
cacheNames.map(function (cacheName) { |
|
|
|
|
|
if (cacheWhitelist.indexOf(cacheName) === -1) { |
|
|
|
|
|
return caches.delete(cacheName); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
}) |
|
|
|
|
|
);*/ |
|
|
|
|
|
event.waitUntil( |
|
|
event.waitUntil( |
|
|
caches.keys().then(function (cacheKeyList) { |
|
|
caches.keys().then(function (cacheKeyList) { |
|
|
return Promise.all( |
|
|
return Promise.all( |
|
|
|
|
|
|
|
|
var dataUrl = 'localhost:8888'; // Provide HTTPS URL for query data. |
|
|
var dataUrl = 'localhost:8888'; // Provide HTTPS URL for query data. |
|
|
console.log('[ServiceWorker] Fetch', event.request.url); |
|
|
console.log('[ServiceWorker] Fetch', event.request.url); |
|
|
|
|
|
|
|
|
if (event.request.url.indexOf(dataUrl) > -1) { |
|
|
|
|
|
|
|
|
//if (event.request.url.indexOf(dataUrl) > -1) { |
|
|
/* |
|
|
/* |
|
|
* When the request URL contains dataUrl, the app is asking for fresh |
|
|
* When the request URL contains dataUrl, the app is asking for fresh |
|
|
* data. In this case, the service worker always goes to the network |
|
|
* data. In this case, the service worker always goes to the network |
|
|
|
|
|
|
|
|
* https://jakearchibald.com/2014/offline-cookbook/#cache-then-network |
|
|
* https://jakearchibald.com/2014/offline-cookbook/#cache-then-network |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
event.respondWith( |
|
|
|
|
|
caches.open(dataCacheKey).then(function (cache) { |
|
|
|
|
|
|
|
|
/*event.respondWith( |
|
|
|
|
|
caches.open(shellCacheKey).then(function (cache) { |
|
|
return fetch(event.request).then(function (response) { |
|
|
return fetch(event.request).then(function (response) { |
|
|
cache.put(event.request.url, response.clone()); |
|
|
cache.put(event.request.url, response.clone()); |
|
|
return response; |
|
|
return response; |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
); |
|
|
); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
/* |
|
|
/* |
|
|
* The app is asking for app shell files. In this scenario the app uses the |
|
|
* The app is asking for app shell files. In this scenario the app uses the |
|
|
* "Cache, falling back to the network" offline strategy: |
|
|
* "Cache, falling back to the network" offline strategy: |
|
|
|
|
|
|
|
|
return response || fetch(event.request); |
|
|
return response || fetch(event.request); |
|
|
}) |
|
|
}) |
|
|
); |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
//} |
|
|
|
|
|
/* |
|
|
|
|
|
caches.match(event.request).then(cachedResponse => { |
|
|
|
|
|
if (cachedResponse) { |
|
|
|
|
|
return cachedResponse; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return caches.open(shellCacheKey).then(cache => { |
|
|
|
|
|
return fetch(event.request).then(response => { |
|
|
|
|
|
// Put a copy of the response in the runtime cache. |
|
|
|
|
|
return cache.put(event.request, response.clone()).then(() => { |
|
|
|
|
|
return response; |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
})*/ |
|
|
}); |
|
|
}); |
|
|
|
|
|
|