This commit is contained in:
2019-04-20 17:30:49 +02:00
parent 7cf7582560
commit ecb9ea25f7
8 changed files with 90 additions and 4 deletions

45
Web/ServiceWorker.js Normal file
View File

@@ -0,0 +1,45 @@
var cacheName = 'CandyFucker-v2';
var filesToCache = [
'./index.html',
'./style.css',
'./code/CandyFucker.js',
'./code/GameLib.js',
'./gfx/BallsBlue.png',
'./gfx/BallsCyan.png',
'./gfx/BallsGreen.png',
'./gfx/BallsRed.png',
'./gfx/BallsYellow.png',
'./gfx/favicon.ico',
'./gfx/favicon.png',
'./gfx/FragsBlue.png',
'./gfx/FragsCyan.png',
'./gfx/FragsGreen.png',
'./gfx/FragsRed.png',
'./gfx/FragsYellow.png',
'./gfx/logo.png',
//'../sfx/explosion1.wav',
//'../sfx/pickcandy.wav',
//'../sfx/swapinvalid.wav',
];
self.addEventListener('install', function (e) {
console.log('[ServiceWorker] Install');
e.waitUntil(
caches.open(cacheName).then(function (cache) {
console.log('[ServiceWorker] Caching app shell');
return cache.addAll(filesToCache);
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request, { ignoreSearch: true }).then(response => {
return response || fetch(event.request);
})
);
});