Skip to content

Commit

Permalink
Merge pull request RocketChat#334 from Shailesh351/sb_fix_pwa_caching
Browse files Browse the repository at this point in the history
Fix First Time Caching Libs in PWA
  • Loading branch information
ear-dev committed Jul 10, 2020
2 parents bf851f7 + 2395d0a commit c77c56f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client/importServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import { Meteor } from 'meteor/meteor';

Meteor.startup(() => {
if ('serviceWorker' in navigator) {
// if (navigator.serviceWorker.controller) {
// console.log('Active service worker found, no need to register');
// } else {
// Register the service worker
navigator.serviceWorker
.register('sw.js', {
scope: './',
})
.then(function(reg) {
if (reg.installing) {
const sw = reg.installing || reg.waiting;
sw.onstatechange = function() {
if (sw.state === 'installed') {
// SW installed. Reload page.
window.location.reload();
}
};
}
console.log(`Service worker has been registered for scope: ${ reg.scope }`);
});
// }
}
});

0 comments on commit c77c56f

Please sign in to comment.