11
11
// opt-in, read https://bit.ly/CRA-PWA
12
12
13
13
const isLocalhost = Boolean (
14
- window . location . hostname === ' localhost' ||
14
+ window . location . hostname === " localhost" ||
15
15
// [::1] is the IPv6 localhost address.
16
- window . location . hostname === ' [::1]' ||
16
+ window . location . hostname === " [::1]" ||
17
17
// 127.0.0.1/8 is considered localhost for IPv4.
18
- window . location . hostname . match (
19
- / ^ 1 2 7 (?: \. (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) { 3 } $ /
20
- )
18
+ window . location . hostname . match ( / ^ 1 2 7 (?: \. (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) { 3 } $ / )
21
19
) ;
22
20
23
21
export function register ( config ) {
24
- if ( process . env . NODE_ENV === ' production' && ' serviceWorker' in navigator ) {
22
+ if ( process . env . NODE_ENV === " production" && " serviceWorker" in navigator ) {
25
23
// The URL constructor is available in all browsers that support SW.
26
24
const publicUrl = new URL ( process . env . PUBLIC_URL , window . location . href ) ;
27
25
if ( publicUrl . origin !== window . location . origin ) {
@@ -31,7 +29,7 @@ export function register(config) {
31
29
return ;
32
30
}
33
31
34
- window . addEventListener ( ' load' , ( ) => {
32
+ window . addEventListener ( " load" , ( ) => {
35
33
const swUrl = `${ process . env . PUBLIC_URL } /service-worker.js` ;
36
34
37
35
if ( isLocalhost ) {
@@ -42,8 +40,8 @@ export function register(config) {
42
40
// service worker/PWA documentation.
43
41
navigator . serviceWorker . ready . then ( ( ) => {
44
42
console . log (
45
- ' This web app is being served cache-first by a service ' +
46
- ' worker. To learn more, visit https://bit.ly/CRA-PWA'
43
+ " This web app is being served cache-first by a service " +
44
+ " worker. To learn more, visit https://bit.ly/CRA-PWA"
47
45
) ;
48
46
} ) ;
49
47
} else {
@@ -64,14 +62,14 @@ function registerValidSW(swUrl, config) {
64
62
return ;
65
63
}
66
64
installingWorker . onstatechange = ( ) => {
67
- if ( installingWorker . state === ' installed' ) {
65
+ if ( installingWorker . state === " installed" ) {
68
66
if ( navigator . serviceWorker . controller ) {
69
67
// At this point, the updated precached content has been fetched,
70
68
// but the previous service worker will still serve the older
71
69
// content until all client tabs are closed.
72
70
console . log (
73
- ' New content is available and will be used when all ' +
74
- ' tabs for this page are closed. See https://bit.ly/CRA-PWA.'
71
+ " New content is available and will be used when all " +
72
+ " tabs for this page are closed. See https://bit.ly/CRA-PWA."
75
73
) ;
76
74
77
75
// Execute callback
@@ -82,7 +80,7 @@ function registerValidSW(swUrl, config) {
82
80
// At this point, everything has been precached.
83
81
// It's the perfect time to display a
84
82
// "Content is cached for offline use." message.
85
- console . log ( ' Content is cached for offline use.' ) ;
83
+ console . log ( " Content is cached for offline use." ) ;
86
84
87
85
// Execute callback
88
86
if ( config && config . onSuccess ) {
@@ -94,7 +92,7 @@ function registerValidSW(swUrl, config) {
94
92
} ;
95
93
} )
96
94
. catch ( error => {
97
- console . error ( ' Error during service worker registration:' , error ) ;
95
+ console . error ( " Error during service worker registration:" , error ) ;
98
96
} ) ;
99
97
}
100
98
@@ -103,11 +101,8 @@ function checkValidServiceWorker(swUrl, config) {
103
101
fetch ( swUrl )
104
102
. then ( response => {
105
103
// Ensure service worker exists, and that we really are getting a JS file.
106
- const contentType = response . headers . get ( 'content-type' ) ;
107
- if (
108
- response . status === 404 ||
109
- ( contentType != null && contentType . indexOf ( 'javascript' ) === - 1 )
110
- ) {
104
+ const contentType = response . headers . get ( "content-type" ) ;
105
+ if ( response . status === 404 || ( contentType != null && contentType . indexOf ( "javascript" ) === - 1 ) ) {
111
106
// No service worker found. Probably a different app. Reload the page.
112
107
navigator . serviceWorker . ready . then ( registration => {
113
108
registration . unregister ( ) . then ( ( ) => {
@@ -120,14 +115,12 @@ function checkValidServiceWorker(swUrl, config) {
120
115
}
121
116
} )
122
117
. catch ( ( ) => {
123
- console . log (
124
- 'No internet connection found. App is running in offline mode.'
125
- ) ;
118
+ console . log ( "No internet connection found. App is running in offline mode." ) ;
126
119
} ) ;
127
120
}
128
121
129
122
export function unregister ( ) {
130
- if ( ' serviceWorker' in navigator ) {
123
+ if ( " serviceWorker" in navigator ) {
131
124
navigator . serviceWorker . ready . then ( registration => {
132
125
registration . unregister ( ) ;
133
126
} ) ;
0 commit comments