diff options
author | Michael <michaelsite12@gmail.com> | 2017-09-15 13:37:34 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2017-09-15 13:37:34 +0300 |
commit | 5951508898b1f92d04026c0038dfc3ba95fa0fdf (patch) | |
tree | 9f823d40b986512f889201e0b90b32cf4e7cf0a5 /assets/js | |
parent | f5368ae00852f114a6bf205afe67e2181ddb2e48 (diff) |
Pre-cache key assets with Workboxjs. (#23533)
Diffstat (limited to 'assets/js')
-rw-r--r-- | assets/js/src/pwa.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/assets/js/src/pwa.js b/assets/js/src/pwa.js index 95ee339482..c3bdd7272c 100644 --- a/assets/js/src/pwa.js +++ b/assets/js/src/pwa.js @@ -7,6 +7,21 @@ window.addEventListener('load', function () { navigator.serviceWorker.register('/sw.js').then(function (registration) { console.log('ServiceWorker registration successful with scope: ', registration.scope) + registration.onupdatefound = function () { + var installingWorker = registration.installing + installingWorker.onstatechange = function () { + switch (installingWorker.state) { + case 'installed': + if (navigator.serviceWorker.controller) { + console.log('new update available') + location.reload(true) + } + break + + default: + } + } + } }).catch(function (err) { console.log('ServiceWorker registration failed: ', err) }) |