var cacheName = 'jd-jaxa-gns-cache-2024-10-20a';
var filesToCache = [
    './',
    './index.html',
    './thg.js',
    './thg.css',
    './img/Yellow.png',
    './img/takara.png',
    './img/koekimap.png',
    './img/osm-koekimap.png',
    './leaflet-1.7.1/leaflet.js',
    './leaflet-1.7.1/leaflet.css',
];
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);
	})
    );
});
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);
	})
    );
});
