|
|
@ -1,6 +1,6 @@ |
|
|
|
import {joinPaths} from '../utils.js'; |
|
|
|
import {joinPaths} from '../utils.js'; |
|
|
|
|
|
|
|
|
|
|
|
const {UseServiceWorker, AppSubUrl, AssetUrlPrefix, AppVer} = window.config; |
|
|
|
const {UseServiceWorker, AssetUrlPrefix, AppVer} = window.config; |
|
|
|
const cachePrefix = 'static-cache-v'; // actual version is set in the service worker script
|
|
|
|
const cachePrefix = 'static-cache-v'; // actual version is set in the service worker script
|
|
|
|
const workerAssetPath = joinPaths(AssetUrlPrefix, 'serviceworker.js'); |
|
|
|
const workerAssetPath = joinPaths(AssetUrlPrefix, 'serviceworker.js'); |
|
|
|
|
|
|
|
|
|
|
@ -41,10 +41,9 @@ export default async function initServiceWorker() { |
|
|
|
// unregister all service workers where scriptURL does not match the current one
|
|
|
|
// unregister all service workers where scriptURL does not match the current one
|
|
|
|
await unregisterOtherWorkers(); |
|
|
|
await unregisterOtherWorkers(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
// normally we'd serve the service worker as a static asset from AssetUrlPrefix but
|
|
|
|
// the spec strictly requires it to be same-origin so the AssetUrlPrefix should contain AppSubUrl
|
|
|
|
// the spec strictly requires it to be same-origin so it has to be AppSubUrl to work
|
|
|
|
|
|
|
|
await checkCacheValidity(); |
|
|
|
await checkCacheValidity(); |
|
|
|
await navigator.serviceWorker.register(joinPaths(AppSubUrl, workerAssetPath)); |
|
|
|
await navigator.serviceWorker.register(workerAssetPath); |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
console.error(err); |
|
|
|
console.error(err); |
|
|
|
await invalidateCache(); |
|
|
|
await invalidateCache(); |
|
|
|