Reputation: 4339
Is there any simple solution to setup serviceWorker in PWA to disable loading from cache when internet is available. I want that app loads from cache only when there is no connection, and if it is online then load from server. Now is situation that serviceWorker doesn't allow refresh even if you click reload (I know how to refresh it for myself but on user side it is problem)... I use default serviceWorker setup with React, but any other solution or example with any other framework would help me.
Upvotes: 1
Views: 3190
Reputation: 1525
Create React App uses Google's Workbox set of libraries for caching. You can read more about it at https://developers.google.com/web/tools/workbox.
In src\index.js
you will find serviceWorker.register()
. Method register accepts config
as argument which you can see in src\serviceWorker.js
but I couldn't find how this argument is structured (any insight would be greatly appreciated).
Upvotes: 1
Reputation: 883
It sounds like you want a "Network First" strategy in your Service Worker. This is documented by Jake Archibald for Google. You can read about it here. This type of Service Worker checks for files on the network before looking at the offline cache.
Upvotes: 4