0
votes

I have a problem with React.

When you doing a create-react-app, you have a file : sercice-worker.js I used a template and this file doesn't exist. I'm trying differents solutions to install service-worker, serviceWorker packages, in mobile, nothing happened. I can't download my application in mobile.

How can I installs service-worker for having the PWA ?

Thx

1
The serviceWorker running only in "production", are you in production? - shai_sharakanski
Yes I have 3 environnements. When I build, I'm in production - Khrra

1 Answers

0
votes

Create a JavaScript file in the public folder of your React project. This file will be your custom service worker. Then register this service worker by using a script placed in the body of your index.html

    if ('serviceWorker' in navigator) {
       window.addEventListener('load', function() {
       navigator.serviceWorker.register('./your-custom-service-worker.js');
       });
    }