(swUrl, config)
| 62 | } |
| 63 | |
| 64 | function checkValidServiceWorker(swUrl, config) { |
| 65 | // Check if the service worker can be found. If it can't reload the page. |
| 66 | fetch(swUrl, { |
| 67 | headers: { 'Service-Worker': 'script' } |
| 68 | }) |
| 69 | .then((response) => { |
| 70 | // Ensure service worker exists, and that we really are getting a JS file. |
| 71 | const contentType = response.headers.get('content-type') |
| 72 | if (response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1)) { |
| 73 | // No service worker found. Probably a different app. Reload the page. |
| 74 | navigator.serviceWorker.ready.then((registration) => { |
| 75 | registration.unregister().then(() => { |
| 76 | window.location.reload() |
| 77 | }) |
| 78 | }) |
| 79 | } else { |
| 80 | // Service worker found. Proceed as normal. |
| 81 | registerValidSW(swUrl, config) |
| 82 | } |
| 83 | }) |
| 84 | .catch(() => { |
| 85 | console.info('No internet connection found. App is running in offline mode.') |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | export function register(config) { |
| 90 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { |
no test coverage detected