diff --git a/inst/pwa-utils/html/offline.html b/inst/pwa-utils/html/offline.html index 937ff9e..431fd1a 100644 --- a/inst/pwa-utils/html/offline.html +++ b/inst/pwa-utils/html/offline.html @@ -10,7 +10,7 @@ Oups - + @@ -43,42 +43,41 @@

Welcome to the offline page

- +
- - - - + + + + + + diff --git a/inst/pwa-utils/js/service-worker.js b/inst/pwa-utils/js/service-worker.js index 7185984..e095a5c 100644 --- a/inst/pwa-utils/js/service-worker.js +++ b/inst/pwa-utils/js/service-worker.js @@ -18,20 +18,27 @@ const CACHE_NAME = "offline"; // Customize this with a different URL if needed. const OFFLINE_URL = "offline.html"; +async function cacheResources() { + const cache = await caches.open(CACHE_NAME); + const resources = [ + new Request(OFFLINE_URL, { cache: "reload" }), + new Request("/shinyMobile-2.0.1/dist/shinyMobile.min.css", { cache: "reload" }), + new Request("/shinyMobile-2.0.1/dist/shinyMobile.min.js", { cache: "reload" }), + new Request("/jquery-3.6.0/jquery.min.js", { cache: "reload" }), + new Request("/shiny-javascript-1.8.1.1/shiny.min.js", { cache: "reload" }) + ]; + + for (const resource of resources) { + try { + await cache.add(resource); + } catch (error) { + console.error(`Failed to cache ${resource.url}:`, error); + } + } +} + self.addEventListener("install", (event) => { - event.waitUntil( - (async () => { - const cache = await caches.open(CACHE_NAME); - // Setting {cache: 'reload'} in the new request will ensure that the - // response isn't fulfilled from the HTTP cache; i.e., it will be from - // the network. - await cache.add( new Request(OFFLINE_URL, { cache: "reload" }) ); - await cache.add( new Request("framework7-5.7.14/css/framework7.bundle.min.css", { cache: "reload" }) ); - await cache.add( new Request("framework7-5.7.14/js/framework7.bundle.min.js", { cache: "reload" }) ); - await cache.add( new Request("shared/jquery.min.js", { cache: "reload" }) ); - })() - ); - // Force the waiting service worker to become the active service worker. + event.waitUntil(cacheResources()); self.skipWaiting(); });