40 lines
847 B
JavaScript
40 lines
847 B
JavaScript
const CACHE_NAME = "msv-moos-webcam-app-v1";
|
|
const URLS_TO_CACHE = [
|
|
"../",
|
|
"../index.html",
|
|
"../css/custom.css",
|
|
"../css/w3.css",
|
|
"../js/webcam.js",
|
|
"../manifest.json",
|
|
"../data/icon.png",
|
|
"../data/favicon.ico"
|
|
];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(URLS_TO_CACHE))
|
|
);
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
event.respondWith(
|
|
caches.match(event.request).then((response) => {
|
|
return response || fetch(event.request);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((cacheNames) =>
|
|
Promise.all(
|
|
cacheNames.map((cache) => {
|
|
if (cache !== CACHE_NAME) {
|
|
return caches.delete(cache);
|
|
}
|
|
})
|
|
)
|
|
)
|
|
);
|
|
});
|