- From: EhsanKey_ <notifications@github.com>
- Date: Wed, 26 Jul 2023 06:51:25 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1689@github.com>
Hello friends, I'm facing an issue with assets caching in browsers. When my project runs on the localhost (Ocak server), the assets are being cached in the browser as expected. However, when I deploy the project, the assets are not getting stored in the static cache as intended. Code: ``` const staticCacheName = "site-static-v2"; const dynamicCacheName = "site-dynamic-v1"; const assets = [ "/", "index.html", "js/app.js", "js/ui.js", "js/db.js", "js/materialize.min.js", "css/styles.css", "css/materialize.min.css", "img/dish.png", "pages/fallback.html", "pages/about.html", "js/class/IndexedDBHandler.js", "https://fonts.googleapis.com/icon?family=Material+Icons", "https://fonts.gstatic.com/s/materialicons/v47/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2", ]; // install event self.addEventListener("install", (evt) => { //console.log('service worker installed'); evt.waitUntil( caches .open(staticCacheName) .then((cache) => { console.log("caching shell assets"); cache.addAll(assets).catch((err) => console.log(err)); }) .catch((err) => console.log(err)) ); }); // activate event self.addEventListener("activate", (evt) => { //console.log('service worker activated'); evt.waitUntil( caches.keys().then((keys) => { //console.log(keys); return Promise.all( keys .filter((key) => key !== staticCacheName && key !== dynamicCacheName) .map((key) => caches.delete(key)) ); }) ); }); ``` Images: ![image_2023-07-26_17-19-14](https://github.com/w3c/ServiceWorker/assets/95970613/bdcc5f01-2c56-4e5e-aa79-9111c7009fa2) ![image_2023-07-26_17-19-38](https://github.com/w3c/ServiceWorker/assets/95970613/0ab3c96d-190a-4230-9e8b-0e58dd7dc771) -- Reply to this email directly or view it on GitHub: https://github.com/w3c/ServiceWorker/issues/1689 You are receiving this because you are subscribed to this thread. Message ID: <w3c/ServiceWorker/issues/1689@github.com>
Received on Wednesday, 26 July 2023 13:51:30 UTC