GeoLeaf Core API - v3.19.0
    Preparing search index...

    Variable SWRegisterConst

    SWRegister: {
        _registration: ServiceWorkerRegistration | null;
        _swPath: string;
        register(
            options?: { path?: string; scope?: string },
        ): Promise<ServiceWorkerRegistration | null>;
        isUpdateWaiting(): boolean;
        applyUpdate(): boolean;
    } = ...

    Type Declaration

    • _registration: ServiceWorkerRegistration | null
    • _swPath: string

      Worker script path. Only one exists in this repo: sw-core.js.

    • register: function
      • Register the Service Worker. No-op in environments that don't support Service Workers.

        Parameters

        • Optionaloptions: { path?: string; scope?: string } = {}
          • Optionalpath?: string

            Script path. ⚠️ No caller sets this parameter: it documented a second worker (sw.js) that never existed in this repo.

          • Optionalscope?: string

            SW scope

        Returns Promise<ServiceWorkerRegistration | null>

        const reg = await SWRegister.register({ scope: "./" });
        
    • isUpdateWaiting: function
      • Is a newer version of the application installed, that this page has not been reloaded onto?

        true in two cases: a new worker WAITS behind the one holding the page, or it already took the page because the update was applied from another tab. false for a first install, before register() has resolved, and where service workers do not exist.

        Returns boolean

        Whether SWRegister.applyUpdate has something to apply.

        if (SWRegister.isUpdateWaiting()) showReloadBanner();
        
    • applyUpdate: function
      • Applies the update the user accepted: the waiting worker takes the page, and the page RELOADS once it holds it — its own code is the old version's.

        ⚠️ The reload is not immediate, and it is not optional: it follows the change of controller, which the worker answers with. Reloading before would boot the old version again. A browser lets the new worker take over once the previous one has no request left in flight — measured: a previous worker waiting on slow tiles held the gesture for more than thirty seconds. Where the update was already applied from another tab, nothing waits any more and the page reloads at once.

        Returns boolean

        true when an update is being applied — the page WILL reload; false when nothing was waiting, and nothing happens.

        reloadButton.addEventListener("click", () => SWRegister.applyUpdate());