I enabled PWA for my reactjs application and deployed on my domain (arvind.inzack.com)
As part of testing, we installed the app on Samsung Tab device. Once the application is loaded successfully we disabled the wifi connection and reloaded the browser. The content in the App is not getting loaded.
we enabled all the files in the cache using Serviceworker.js
let CACHE_NAME = 'my-site-cache-v1';
const urlsToCache = [
'/',
'/index.html',
];
const precacheadd1Resources = ['/', '/shirt-trouser/shirts/.jpeg', '/shirt-trouser/shirts/.JPG', '/shirt-trouser/shirts/.PNG', '/shirt-trouser/shirts/.png'];
const precacheadd2Resources = ['/', '/shirt-trouser/trouser_plain/.jpeg', '/shirt-trouser/trouser_plain/.JPG', '/shirt-trouser/trouser_plain/.PNG', '/shirt-trouser/trouser_plain/.png'];
const precacheadd3Resources = ['/', '/shirt-trouser/belt/.jpeg', '/shirt-trouser/belt/.JPG', '/shirt-trouser/belt/.PNG', '/shirt-trouser/belt/.png'];
const precacheadd4Resources = ['/config.js', '/index.js','App.js','components/BabylonAvatar.js','components/SceneComponent.js'];
const precacheadd5Resources = ['/avatar/newformalwalk13.glb'];
window.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache,
precacheadd1Resources,
precacheadd2Resources,
precacheadd3Resources,
precacheadd4Resources,
precacheadd5Resources);
})
);
});
Please suggest how can we using the PWA App in offline mode.
I am trying with sw-toolbox cache, Using this link am trying to integrate
can somebody share the approach how to integrate sw-toolbox with with reactjs
Thanks Asha
I see that you cache the resources, but
activate
andfetch
listeners are missing. Thefetch
listener is triggered on each network request to cache and serve cached assets.This is how my sw.js looks like:
Notice how I precached all the necessary resources for the offline mode, now in
fetch
listener:I try to get a cached resource;
if resource is not cached - I try to fetch it;
if there is no internet connection - I request cached
/offline
page;