fix: update PWA workers without reloading pages
This commit is contained in:
@@ -312,18 +312,12 @@ export function renderPwaClient(version = "2") {
|
||||
swUrl = window.trustedTypes.createPolicy("wrnexus-pwa", { createScriptURL: function(value) { return value; } }).createScriptURL(swUrl);
|
||||
} catch (_) {}
|
||||
}
|
||||
var reloading = false;
|
||||
navigator.serviceWorker.addEventListener("controllerchange", function () {
|
||||
var key = "wrnexus-pwa-controller-" + swVersion;
|
||||
if (reloading || sessionStorage.getItem(key)) return;
|
||||
reloading = true;
|
||||
sessionStorage.setItem(key, "1");
|
||||
location.reload();
|
||||
});
|
||||
addEventListener("load", function () {
|
||||
navigator.serviceWorker.register(swUrl, { updateViaCache: "none" }).then(function (registration) {
|
||||
return registration.update();
|
||||
}).catch(function () {});
|
||||
var register = function () {
|
||||
navigator.serviceWorker.register(swUrl, { updateViaCache: "none" }).catch(function () {});
|
||||
};
|
||||
if ("requestIdleCallback" in window) window.requestIdleCallback(register, { timeout: 2000 });
|
||||
else setTimeout(register, 0);
|
||||
});
|
||||
}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user