Skip to content

Commit

Permalink
fix(service-worker): Install service worker correctly (#222)
Browse files Browse the repository at this point in the history
* fix(service-worker): register service worker immediately
  • Loading branch information
jeremyckahn authored Dec 12, 2023
1 parent d697aa0 commit d546fef
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/serviceWorkerRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,24 @@ export function register(config) {
return
}

window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config)
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config)

// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://cra.link/PWA'
)
})
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config)
}
})
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://cra.link/PWA'
)
})
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config)
}
}
}

Expand Down

1 comment on commit d546fef

@vercel
Copy link

@vercel vercel bot commented on d546fef Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chitchatter – ./

chitchatter.vercel.app
chitchatter-jeremyckahn.vercel.app
chitchatter-git-main-jeremyckahn.vercel.app

Please sign in to comment.