mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
Enhanced offline (#249)
* Notification of updates & reloading * Using version in service worker & allowing version to appear elsewhere * Stupid file * Ditching changelog for now. Using package json. * Ugh.
This commit is contained in:
@@ -8,8 +8,7 @@ declare var self: ServiceWorkerGlobalScope;
|
||||
// This is populated by webpack.
|
||||
declare var BUILD_ASSETS: string[];
|
||||
|
||||
const version = '1.0.0';
|
||||
const versionedCache = 'static-' + version;
|
||||
const versionedCache = 'static-' + VERSION;
|
||||
const dynamicCache = 'dynamic';
|
||||
const expectedCaches = [versionedCache, dynamicCache];
|
||||
|
||||
@@ -28,6 +27,8 @@ self.addEventListener('install', (event) => {
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
self.clients.claim();
|
||||
|
||||
event.waitUntil(async function () {
|
||||
// Remove old caches.
|
||||
const promises = (await caches.keys()).map((cacheName) => {
|
||||
@@ -57,7 +58,12 @@ self.addEventListener('fetch', (event) => {
|
||||
});
|
||||
|
||||
self.addEventListener('message', (event) => {
|
||||
if (event.data === 'cache-all') {
|
||||
event.waitUntil(cacheAdditionalProcessors(versionedCache, BUILD_ASSETS));
|
||||
switch (event.data) {
|
||||
case 'cache-all':
|
||||
event.waitUntil(cacheAdditionalProcessors(versionedCache, BUILD_ASSETS));
|
||||
break;
|
||||
case 'skip-waiting':
|
||||
self.skipWaiting();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user