Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt for update - updateSW() - assets fetched from network #25

Open
juhasev opened this issue Feb 14, 2023 · 0 comments
Open

Prompt for update - updateSW() - assets fetched from network #25

juhasev opened this issue Feb 14, 2023 · 0 comments

Comments

@juhasev
Copy link

juhasev commented Feb 14, 2023

According to the manual:

"When the user clicks the "refresh" button when onNeedRefresh is called, then calls updateSW() function; the page will reload, and the up-to-date content will be served."

Yes, this works, but all the assets are loaded from the network even though the service worker has cached them all. This makes the application feel sluggish after each update. When you first open the app, the service worker immediately goes to work, and all assets are correctly cached. But the caching breaks when updateSW() is called. Is this a bug am I missing out on something?

My JS code is identical to the example given in the documentation.

const updateSW = registerSW({

    immediate: true,

    // Shows UPDATE button in the top toolbar
    onNeedRefresh() {
        Bus.$emit('show-reload');
    },

    onRegisteredSW(swUrl, registered) {
        registered && setInterval(async () => {

            if (!(!registered.installing && navigator)) return
            if (('connection' in navigator) && !navigator.onLine) return

            const resp = await fetch(swUrl, {
                cache: 'no-store',
                headers: {
                    'cache': 'no-store',
                    'cache-control': 'no-cache',
                },
            })

            if (resp?.status === 200) {
                await registered.update();
            }

        }, intervalMS)
    },
})

// When user click on the update button we will execute updateSW() that
// activate the new SW reloads pre-cache + reloads the page
Bus.$on('update-approved', () => {
    updateSW();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant