i am trying to make offline mode for my react app. i store data in cache and trying to restore it when there is no network but i dont know what is the issus and i am unable to load it here is my code kindly have a look and let me know . thanks in advance.
//for storing in cache
let cacheData = "appV1";
this.addEventListener("install", (event) => {
event.waitUntil(
caches.open(cacheData).then((cache) => {
cache.addAll([
"/static/js/main.chunk.js",
"/static/js/0.chunk.js",
"/static/js/bundle.js",
"/static/css/main.chunk.css",
"/index.html",
"/",
]);
})
);
});
//for restoring from cache in Offline mode
this.addEventListener("fetch", (event) => {
console.log("caches", caches);
event.respondWith(
caches.match(event.request).then((resp) => {
if (resp) {
return resp;
}
})
);
});