@@ -17,27 +17,38 @@ export default function register() {
17
17
// No service worker yet
18
18
registerServiceWorker ( swUrl ) ;
19
19
} else {
20
- fetch ( swUrl ) . then ( res => {
21
- // Check to see if the SW URL is valid
22
- if ( res . ok ) {
23
- // Matches. All good. Continue with registering SW
24
- registerServiceWorker ( swUrl ) ;
25
- } else {
26
- // SW URL was invalid.
27
- fetch (
28
- `${ window . location . protocol } //${ window . location . host } `
29
- ) . then ( res2 => {
30
- // Just check if online
31
- if ( res2 . ok ) {
32
- // Unregister and refresh page
33
- unregister ( ) ;
34
- window . location . reload ( true ) ;
35
- } else {
36
- console . log ( 'Offline. Using cached copy' ) ;
37
- }
38
- } ) ;
39
- }
40
- } ) ;
20
+ fetch ( swUrl )
21
+ . then ( res => {
22
+ // Check to see if the SW URL is valid
23
+ if ( res . ok ) {
24
+ // Matches. All good. Continue with registering SW
25
+ registerServiceWorker ( swUrl ) ;
26
+ } else {
27
+ // SW URL was invalid.
28
+ fetch ( `${ window . location . protocol } //${ window . location . host } ` )
29
+ . then ( res2 => {
30
+ // Just check if online
31
+ if ( res2 . ok ) {
32
+ // Unregister and refresh page
33
+ unregister ( ) ;
34
+ window . location . reload ( true ) ;
35
+ } else {
36
+ console . log ( 'Offline. Using cached copy' ) ;
37
+ }
38
+ } )
39
+ . catch ( err => {
40
+ // Host down. Do nothing.
41
+ console . log (
42
+ `Caught - fetch ${ window . location . protocol } //${ window . location . host } ` ,
43
+ err
44
+ ) ;
45
+ } ) ;
46
+ }
47
+ } )
48
+ . catch ( err => {
49
+ // Couldn't access service worker url becaose of timeout/fetch error. Do nothing.
50
+ console . log ( `Caught - fetch ${ swUrl } ` , err ) ;
51
+ } ) ;
41
52
}
42
53
} ) ;
43
54
}
@@ -47,7 +58,7 @@ function registerServiceWorker(url) {
47
58
navigator . serviceWorker
48
59
. register ( url )
49
60
. then ( registration => {
50
- console . log ( 'reg.scope ' , registration . scope ) ;
61
+ console . log ( 'register ' , registration ) ;
51
62
registration . onupdatefound = ( ) => {
52
63
const installingWorker = registration . installing ;
53
64
installingWorker . onstatechange = ( ) => {
0 commit comments