-
-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Closed
Labels
Description
I just created the react-app by following the command:
create-react-app test
Now I want to play with service worker concepts in Dev mode. So I decided to write a simple service worker registration code over here:
export default function registerServiceWorker()
{
if('serviceWorker' in navigator) {
navigator.serviceWorker.register(`${process.env.PUBLIC_URL}/service-worker.js`).then(function(register){
console.log("worked", register);
}).catch(function(err){
console.log("error!")
});
}
}
And I registered by calling the function registerServiceWorker. Looks like the registration function works smoothly (as I could able to see the worked on the console log). However, I cannot see my real service-worker.js is called!
service-worker.js file looks like:
var cacheName = ‘helloWorld’;
self.addEventListener('install', event => { event.waitUntil(
caches.open(cacheName).then(cache => cache.addAll([
'/js/script.js',
'/images/hello.png' ]))
);
});
But the caching is not working as I had given above in the code. Debugging shows that the service-worker.js file which is loaded by the browser something else. Not sure what mistake I'm making here. May be this is an issue?
Note I'm running the application using npm start
Thanks for the help.