I am looking at implementing my web application as a PWA using React. The main feature that I want to implement is to cache JSON data fetched from API such that it works in offline mode. However, I do not know how to code the service worker in React.
Asked
Active
Viewed 595 times
0
-
Well, there's a bunch of articles and videos showing how to make React based PWAs and examples of service workers, just a google search away. I'd start there, then come back if you have any specific questions. – Jayce444 Jul 18 '19 at 01:41
1 Answers
1
You can start reading the official doc here and you should figure out how you must configure your environment (webpack). If you could not understand it, you shoud read this medium article here or here.
You need to:
- Create the file manifest.json or generate it.
- Bind the manifest.json at the header section:
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
- Create a file registerServiceWorker.js, you can find help here
- Write your React App.
- Choose an offline strategy to store data (for example, you can use redux offline or redux persist).
Mauro Stepanoski
- 715
- 6
- 9