var cacheName = "mobile_web_bible";
var resourceList = [
    "mobile_web_bible.html",
    "sw.js",
    "js/bootstrap.min.js",
    "js/bootstrap.min.js.map",
    "js/jquery.min.js",
    "js/sql-wasm.js",
    "js/sql-wasm.wasm",
    "js/swiped-events.min.js",
    "css/bootstrap.min.css",
    "css/bootstrap.min.css.map",
    "html/menu.html",
    "html/search.html",
    "html/select_book.html",
    "html/select_chapter.html",
    "html/viewer.html",
    "json/toc.json",
    "sql/cht_unv.db"
];

self.addEventListener("install", event => {
    event.waitUntil(
        caches.open(cacheName).then(cache => {
            return cache.addAll(resourceList).then(() => self.skipWaiting());
        })
    );
});

self.addEventListener("activate", event => {
    event.waitUntil(self.clients.claim());
});

self.addEventListener("fetch", event => {
    event.respondWith(
        caches.open(cacheName)
            .then(cache => cache.match(event.request, {ignoreSearch: true}))
            .then(response => {
            return response || fetch(event.request);
            })
    );
});
