Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 60604c9

Browse files
service worker code file some changes done
1 parent 7a3b2fe commit 60604c9

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

public/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
<meta name="theme-color" content="#000000" />
88
<meta name="description" content="Todo App" />
99
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
10+
<!-- <link rel="apple-touch-icon" href="./logo192.png" /> -->
1011
<!--
1112
manifest.json provides metadata used when your web app is installed on a
1213
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1314
-->
1415
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!-- <link rel="manifest" href="./manifest.json" /> -->
1517
<!--
1618
Notice the use of %PUBLIC_URL% in the tags above.
1719
It will be replaced with the URL of the `public` folder during the build.
@@ -41,7 +43,9 @@
4143
window.addEventListener('load', () => {
4244
console.log('serviceWorker custom');
4345
navigator.serviceWorker
44-
.register('./my-serviceworker.js')
46+
.register('./my-serviceworker.js', {
47+
// scope: '.', // <--- THIS BIT IS REQUIRED
48+
})
4549
.then((reg) => console.log('Success: ', reg.scope))
4650
.catch((err) => console.log('Failure: ', err));
4751
});

public/my-serviceworker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const CACHE_NAME = 'version-1';
22
const urlsToCache = [
3+
'/',
34
'index.html',
45
'offline.html',
56
'https://todo-restapi-app.herokuapp.com/api/todos',

src/serviceWorker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export function register(config) {
3434
window.addEventListener('load', () => {
3535
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
3636

37+
console.log('swUrl', swUrl);
3738
if (isLocalhost) {
39+
console.log('if part');
3840
// This is running on localhost. Let's check if a service worker still exists or not.
3941
checkValidServiceWorker(swUrl, config);
4042

@@ -48,6 +50,7 @@ export function register(config) {
4850
});
4951
} else {
5052
// Is not localhost. Just register service worker
53+
console.log('else part');
5154
registerValidSW(swUrl, config);
5255
}
5356
});
@@ -58,6 +61,7 @@ function registerValidSW(swUrl, config) {
5861
navigator.serviceWorker
5962
.register(swUrl)
6063
.then((registration) => {
64+
console.log('react sw working ........ . . . . . .');
6165
registration.onupdatefound = () => {
6266
console.log('serviceWorker working');
6367
const installingWorker = registration.installing;

0 commit comments

Comments
 (0)