moth/theme/moth-pwa.js

18 lines
460 B
JavaScript
Raw Permalink Normal View History

2019-10-25 16:53:40 -06:00
function pwa_init() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("./sw.js").then(function(reg) {
})
.catch(err => {
2019-11-04 09:22:44 -07:00
console.warn("Error while registering service worker", err)
})
2019-10-25 16:53:40 -06:00
} else {
2019-11-04 09:22:44 -07:00
console.log("Service workers not supported. Some offline functionality may not work")
2019-10-25 16:53:40 -06:00
}
}
if (document.readyState === "loading") {
2019-11-04 09:22:44 -07:00
document.addEventListener("DOMContentLoaded", pwa_init)
2019-10-25 16:53:40 -06:00
} else {
2019-11-04 09:22:44 -07:00
pwa_init()
2019-10-25 16:53:40 -06:00
}