@@ -44,10 +44,10 @@ export function register(config?: Config) {
4444 // Add some additional logging to localhost, pointing developers to the
4545 // service worker/PWA documentation.
4646 navigator . serviceWorker . ready . then ( ( ) => {
47- console . log (
48- 'This web app is being served cache-first by a service ' +
49- 'worker. To learn more, visit https://cra.link/PWA'
50- ) ;
47+ // console.log(
48+ // 'This web app is being served cache-first by a service ' +
49+ // 'worker. To learn more, visit https://cra.link/PWA'
50+ // );
5151 } ) ;
5252 } else {
5353 // Is not localhost. Just register service worker
@@ -58,85 +58,81 @@ export function register(config?: Config) {
5858}
5959
6060function registerValidSW ( swUrl : string , config ?: Config ) {
61- navigator . serviceWorker
62- . register ( swUrl )
63- . then ( ( registration ) => {
64- registration . onupdatefound = ( ) => {
65- const installingWorker = registration . installing ;
66- if ( installingWorker == null ) {
67- return ;
68- }
69- installingWorker . onstatechange = ( ) => {
70- if ( installingWorker . state === 'installed' ) {
71- if ( navigator . serviceWorker . controller ) {
72- // At this point, the updated precached content has been fetched,
73- // but the previous service worker will still serve the older
74- // content until all client tabs are closed.
75- console . log (
76- 'New content is available and will be used when all ' +
77- 'tabs for this page are closed. See https://cra.link/PWA.'
78- ) ;
61+ navigator . serviceWorker . register ( swUrl ) . then ( ( registration ) => {
62+ registration . onupdatefound = ( ) => {
63+ const installingWorker = registration . installing ;
64+ if ( installingWorker == null ) {
65+ return ;
66+ }
67+ installingWorker . onstatechange = ( ) => {
68+ if ( installingWorker . state === 'installed' ) {
69+ if ( navigator . serviceWorker . controller ) {
70+ // At this point, the updated precached content has been fetched,
71+ // but the previous service worker will still serve the older
72+ // content until all client tabs are closed.
73+ // console.log(
74+ // 'New content is available and will be used when all ' +
75+ // 'tabs for this page are closed. See https://cra.link/PWA.'
76+ // );
7977
80- // Execute callback
81- if ( config && config . onUpdate ) {
82- config . onUpdate ( registration ) ;
83- }
84- } else {
85- // At this point, everything has been precached.
86- // It's the perfect time to display a
87- // "Content is cached for offline use." message.
88- console . log ( 'Content is cached for offline use.' ) ;
78+ // Execute callback
79+ if ( config && config . onUpdate ) {
80+ config . onUpdate ( registration ) ;
81+ }
82+ } else {
83+ // At this point, everything has been precached.
84+ // It's the perfect time to display a
85+ // "Content is cached for offline use." message.
86+ // console.log('Content is cached for offline use.');
8987
90- // Execute callback
91- if ( config && config . onSuccess ) {
92- config . onSuccess ( registration ) ;
93- }
88+ // Execute callback
89+ if ( config && config . onSuccess ) {
90+ config . onSuccess ( registration ) ;
9491 }
9592 }
96- } ;
93+ }
9794 } ;
98- } )
99- . catch ( ( error ) => {
100- console . error ( 'Error during service worker registration:' , error ) ;
101- } ) ;
95+ } ;
96+ } ) ;
97+ // .catch((error) => {
98+ // console.error('Error during service worker registration:', error);
99+ // });
102100}
103101
104102function checkValidServiceWorker ( swUrl : string , config ?: Config ) {
105103 // Check if the service worker can be found. If it can't reload the page.
106104 fetch ( swUrl , {
107105 headers : { 'Service-Worker' : 'script' }
108- } )
109- . then ( ( response ) => {
110- // Ensure service worker exists, and that we really are getting a JS file.
111- const contentType = response . headers . get ( 'content-type' ) ;
112- if (
113- response . status === 404 ||
114- ( contentType != null && contentType . indexOf ( 'javascript' ) === - 1 )
115- ) {
116- // No service worker found. Probably a different app. Reload the page.
117- navigator . serviceWorker . ready . then ( ( registration ) => {
118- registration . unregister ( ) . then ( ( ) => {
119- window . location . reload ( ) ;
120- } ) ;
106+ } ) . then ( ( response ) => {
107+ // Ensure service worker exists, and that we really are getting a JS file.
108+ const contentType = response . headers . get ( 'content-type' ) ;
109+ if (
110+ response . status === 404 ||
111+ ( contentType != null && contentType . indexOf ( 'javascript' ) === - 1 )
112+ ) {
113+ // No service worker found. Probably a different app. Reload the page.
114+ navigator . serviceWorker . ready . then ( ( registration ) => {
115+ registration . unregister ( ) . then ( ( ) => {
116+ window . location . reload ( ) ;
121117 } ) ;
122- } else {
123- // Service worker found. Proceed as normal.
124- registerValidSW ( swUrl , config ) ;
125- }
126- } )
127- . catch ( ( ) => {
128- console . log ( 'No internet connection found. App is running in offline mode.' ) ;
129- } ) ;
118+ } ) ;
119+ } else {
120+ // Service worker found. Proceed as normal.
121+ registerValidSW ( swUrl , config ) ;
122+ }
123+ } ) ;
124+ // .catch(() => {
125+ // console.log('No internet connection found. App is running in offline mode.');
126+ // });
130127}
131128
132129export function unregister ( ) {
133130 if ( 'serviceWorker' in navigator ) {
134- navigator . serviceWorker . ready
135- . then ( ( registration ) => {
136- registration . unregister ( ) ;
137- } )
138- . catch ( ( error ) => {
139- console . error ( error . message ) ;
140- } ) ;
131+ navigator . serviceWorker . ready . then ( ( registration ) => {
132+ registration . unregister ( ) ;
133+ } ) ;
134+ // .catch((error) => {
135+ // console.error(error.message);
136+ // });
141137 }
142138}
0 commit comments