var cacheName = 'MapGame-1/10-1';
var filesToCache = [
    './MapGame.html',
    './MapGame.js',
    './shooter.js',
    './img/mapapp.png',
    './img/favicon.ico'
];
self.addEventListener('install', function(event) {
    console.log('ServiceWorker installing');
    event.waitUntil(
	caches.open(cacheName).then(function(cache) {
	    console.log('Service Worker caching app shell');
	    return cache.addAll(filesToCache).catch(function(error) {
                console.error('Failed to cache resources:', error);
                return Promise.reject(error);
            });
                
	})
    );
});
self.addEventListener('activate', function(event) {
    console.log('Service Worker activating');
    event.waitUntil(
	caches.keys().then(function(keyList) {
	    return Promise.all(keyList.map(function(key) {
		if (key !== cacheName) {
		    console.log('Service Worker removing old cache', key);
		    return caches.delete(key);
		}
	    }));
	})
    );
    return self.clients.claim();
});
self.addEventListener('fetch', function(event) {
    console.log('Service Worker fetching', event.request.url);
    event.respondWith(
	caches.match(event.request).then(function(response) {
	    return response || fetch(event.request);
	})
    );
});
