2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-14 18:42:30 +03:00

Pre-cache key assets with Workboxjs. (#23533)

This commit is contained in:
Michael
2017-09-15 11:37:34 +01:00
committed by XhmikosR
parent f5368ae008
commit 5951508898
6 changed files with 2186 additions and 284 deletions
+15
View File
@@ -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)
})