(swUrl)
| 73 | } |
| 74 | |
| 75 | function checkValidServiceWorker(swUrl) { |
| 76 | // Check if the service worker can be found. If it can't reload the page. |
| 77 | fetch(swUrl) |
| 78 | .then(response => { |
| 79 | // Ensure service worker exists, and that we really are getting a JS file. |
| 80 | if ( |
| 81 | response.status === 404 || |
| 82 | response.headers.get('content-type').indexOf('javascript') === -1 |
| 83 | ) { |
| 84 | // No service worker found. Probably a different app. Reload the page. |
| 85 | navigator.serviceWorker.ready.then(registration => { |
| 86 | registration.unregister().then(() => { |
| 87 | window.location.reload(); |
| 88 | }); |
| 89 | }); |
| 90 | } else { |
| 91 | // Service worker found. Proceed as normal. |
| 92 | registerValidSW(swUrl); |
| 93 | } |
| 94 | }) |
| 95 | .catch(() => { |
| 96 | console.log( |
| 97 | 'No internet connection found. App is running in offline mode.' |
| 98 | ); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | export function unregister() { |
| 103 | if ('serviceWorker' in navigator) { |
no test coverage detected