Skip to content

Commit

Permalink
Add service worker for PWA (#972)
Browse files Browse the repository at this point in the history
Fix resolution mismatch in manifest.webmanifest
Add service worker
Embed service worker registration in `src/bootstrap.ts` and enable console output
  • Loading branch information
chrisly-bear committed Mar 17, 2020
1 parent 168c603 commit 7bb2ba0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"icons": [
{
"src": "img/favicon/favicon.ico?v=[[VERSION]]",
"sizes": "64x64",
"sizes": "48x48",
"type": "image/x-icon"
},
{
Expand Down
16 changes: 16 additions & 0 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// service worker for PWA (progressive web app)

self.addEventListener('install', (event) => {
// console.log('👷', 'install', event);
self.skipWaiting();
});

self.addEventListener('activate', (event) => {
// console.log('👷', 'activate', event);
return self.clients.claim();
});

self.addEventListener('fetch', function (event) {
// console.log('👷', 'fetch', event);
event.respondWith(fetch(event.request));
});
10 changes: 10 additions & 0 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
import('./app')
.then(() => {
console.info('Bundle loaded, bootstrapping application.');
// register service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(function (registration) {
console.info('Service worker registration successful, scope is:', registration.scope);
})
.catch(function (error) {
console.warn('Service worker registration failed, error:', error);
});
}
angular.bootstrap(document, ['3ema']);
})
.catch((e) => console.error('Could not bootstrap application', e));

0 comments on commit 7bb2ba0

Please sign in to comment.