优化findServiceWorker写法
This commit is contained in:
parent
cd2b07a48d
commit
054afb0976
|
@ -144,12 +144,9 @@ new Promise(resolve => {
|
||||||
if (location.protocol.startsWith('http') && 'serviceWorker' in navigator) {
|
if (location.protocol.startsWith('http') && 'serviceWorker' in navigator) {
|
||||||
let scope = window.location.protocol + '//' + window.location.host + '/';
|
let scope = window.location.protocol + '//' + window.location.host + '/';
|
||||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||||
let findServiceWorker = false;
|
let findServiceWorker = registrations.find(registration => {
|
||||||
for (let registration of registrations) {
|
return registration && registration.active && registration.active.scriptURL == `${scope}service-worker.js`;
|
||||||
if (registration && registration.active && registration.active.scriptURL == `${scope}service-worker.js`) {
|
})
|
||||||
findServiceWorker = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
navigator.serviceWorker.register(`${scope}service-worker.js`, {
|
navigator.serviceWorker.register(`${scope}service-worker.js`, {
|
||||||
updateViaCache: "all",
|
updateViaCache: "all",
|
||||||
scope,
|
scope,
|
||||||
|
|
Loading…
Reference in New Issue