Last active
September 28, 2018 23:33
-
-
Save ademidun/99ff43d46cd6753be83ee0f1e223a8c5 to your computer and use it in GitHub Desktop.
Service worker configuration for Part 1 if Angular pwa tutorial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/main.ts | |
import { enableProdMode } from '@angular/core'; | |
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | |
import { AppModule } from './app/app.module'; | |
import { environment } from './environments/environment'; | |
if (environment.production) { | |
enableProdMode(); | |
} | |
platformBrowserDynamic().bootstrapModule(AppModule) | |
.catch(err => console.log(err)); | |
// ** New Code ** // | |
// https://github.com/angular/angular-cli/issues/9021 | |
// https://blog.angular-university.io/service-workers/ | |
// https://juristr.com/blog/2018/01/ng-app-runtime-config/ | |
if ('serviceWorker' in navigator && environment.production) { | |
console.log("Service Worker in main.ts"); | |
window.addEventListener('load', () => { | |
console.log("on page Load Service Worker in main.ts"); | |
navigator.serviceWorker.register('/ngsw-worker.js', { | |
scope: '/', | |
}) | |
.then(registration => { | |
console.log("Service Worker registration completed main.ts", registration); | |
}); | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Atila", | |
"short_name": "Atila", | |
"start_url": "index.html", | |
"display": "standalone", | |
"icons": [{ | |
"src": "assets/img/favicon-bg.png", | |
"sizes": "512x512", | |
"type": "image/png" | |
}], | |
"background_color": "#194f87", | |
"theme_color": "#194f87" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"index": "/index.html", | |
"assetGroups": [{ | |
"name": "app", | |
"installMode": "prefetch", | |
"resources": { | |
"files": [ | |
"/favicon.ico", | |
"/index.html", | |
"/*.css", | |
"/*.js" | |
] | |
} | |
}, { | |
"name": "assets", | |
"installMode": "lazy", | |
"updateMode": "prefetch", | |
"resources": { | |
"files": [ | |
"/assets/**" | |
] | |
} | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"index": "/index.html", | |
"assetGroups": [{ | |
"name": "app", | |
"installMode": "prefetch", | |
"resources": { | |
"files": [ | |
"/favicon.ico", | |
"/index.html", | |
"/*.css", | |
"/*.js" | |
], | |
"urls": [ | |
"https://firebasestorage.googleapis.com/v0/b/atila-7.appspot.com/o/user-profiles%2F1%2Fprofile-pictures%2Ffacebook-profile-picture.jpg?alt=media&token=8754c657-bbdc-4d8e-ae1d-d4047ac09c6d", | |
"https://lh6.googleusercontent.com/U1oHmeuzUcMbPLHFhpDHc_8KsFWq7IX_jE6kUBl1svTSnffIukAjJ0QDgfXJCdZ_rONXiZzhtNnz3CrFMDEnrIrMc5MpnWcSuUfEURbNRFM9lxYPN6qDMSMHPqC02h9o0pO9UlUP", | |
"https://atila-7.herokuapp.com/api/blog/blog-slug/tomiwa/how-i-got-interviews-at-google-facebook-and-bridgewater/", | |
"https://api.myjson.com/bins/18mldc" | |
] | |
} | |
}, { | |
"name": "assets", | |
"installMode": "lazy", | |
"updateMode": "prefetch", | |
"resources": { | |
"files": [ | |
"/assets/**" | |
] | |
} | |
}], | |
"dataGroups": [ | |
{ | |
"name": "demo.atila.ca", | |
"urls": [ | |
"https://atila-7.herokuapp.com/api/**", | |
"https://api.myjson.com/bins/**" | |
], | |
"cacheConfig": { | |
"maxSize": 3, | |
"maxAge": "7d", | |
"strategy": "freshness" | |
} | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment