ToolkitLabs.dev/service-worker.js

44 строки
1.4 KiB
JavaScript
Исходник Обычный вид История

2024-03-29 18:58:08 +03:00
import { config } from "./package_44f89837f3c2d99d0c0f81b772fe861833ffbd66//uno-config.js";
2022-07-18 00:34:57 +03:00
console.debug("[ServiceWorker] Initializing");
2022-07-18 00:34:57 +03:00
self.addEventListener('install', function (e) {
console.debug('[ServiceWorker] Installing offline worker');
e.waitUntil(
2024-03-29 18:58:08 +03:00
caches.open('package_44f89837f3c2d99d0c0f81b772fe861833ffbd66').then(async function (cache) {
console.debug('[ServiceWorker] Caching app binaries and content');
// Add files one by one to avoid failed downloads to prevent the
// worker to fail installing.
for (var i = 0; i < config.offline_files.length; i++) {
try {
await cache.add(config.offline_files[i]);
}
catch (e) {
console.debug(`[ServiceWorker] Failed to fetch ${config.offline_files[i]}`);
2022-07-18 00:34:57 +03:00
}
}
})
2022-07-18 00:34:57 +03:00
);
});
self.addEventListener('activate', event => {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', event => {
event.respondWith(async function () {
try {
// Network first mode to get fresh content every time, then fallback to
// cache content if needed.
return await fetch(event.request);
} catch (err) {
return caches.match(event.request).then(response => {
return response || fetch(event.request);
});
}
}());
});
// managed