Skip to content

Commit

Permalink
update serviceworker
Browse files Browse the repository at this point in the history
  • Loading branch information
vnglst committed Mar 15, 2019
1 parent 094a5d8 commit 1c810ec
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/registerServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:no-console
// In production, we register a service worker to serve assets from local cache.

// This lets the app load faster on subsequent visits in production, and gives
Expand All @@ -14,16 +15,16 @@ const isLocalhost = Boolean(
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
),
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
)

export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
process.env.PUBLIC_URL!,
window.location.toString(),
window.location.toString()
)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
Expand All @@ -44,7 +45,7 @@ export default function register() {
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://goo.gl/SC7cgQ',
'worker. To learn more, visit https://goo.gl/SC7cgQ'
)
})
} else {
Expand Down Expand Up @@ -108,7 +109,7 @@ function checkValidServiceWorker(swUrl: string) {
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.',
'No internet connection found. App is running in offline mode.'
)
})
}
Expand Down

0 comments on commit 1c810ec

Please sign in to comment.