question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Old vuepress service worker cached

See original GitHub issue

Describe the bug

Hi👋

Amazing work with vitepress! Thanks for that!

I have a small issue with my docs site. I used to have a vuepress app running my old docs and switched to vitepress. Some users are still seeing the same old site (vuepress) when they navigate to a URL instead of the new one (vitepress).

My question is: How can I bust the client cache from the server?

The website is https://docs.avohq.io/ and it’s hosted on netlify.

Thank you,

Reproduction

I can’t offer a reproduction unless you’ve previously visited the old site.

Expected behavior

The new site (vitepress) should be visible, not the old one (vuepress).

System Info

System:
    OS: macOS 12.6
    CPU: (10) x64 Apple M1 Max
    Memory: 40.16 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.20.0 - ~/.nvm/versions/node/v14.20.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.20.0/bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.20.0/bin/npm
  Browsers:
    Chrome: 106.0.5249.119
    Firefox: 104.0
    Safari: 16.0
    Safari Technology Preview: 16.0
  npmPackages:
    vitepress: ^1.0.0-alpha.19 => 1.0.0-alpha.19

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kiakingcommented, Oct 20, 2022

@adrianthedev Issues are for actual issues (bug reports) or feature requests. When you say “Some users are still seeing the same old site…” this is not a VitePress problem. VitePress has nothing to do with your old site. So it sounds very much like your hosting service settings issue.

For those questions would be better handled in Discord or in Discussions. You can join Vue.js Official Discord here (which has VitePress channel). https://discord.com/invite/HBherRA

0reactions
BasilaryGroupcommented, Nov 26, 2022

Sorry for adding to a closed issue.

I was able to track down the Discord discussion related to this problem and I thought it would help others who face the same problem.

You have an existing VuePress site deployed on a host like netlify, gitlab pages, github, etc. You deploy your new VitePress site and the old site keeps displaying.

  1. assumes you have defined a base: /yourbaseurl/ in docs/.vitepress/config.js
  2. copy your old manifest.json into docs/public/manifest.json
  3. in docs/.vitepress/config.js add a header: [] section containing
    head: [
        ['link', { rel: 'manifest', href: '/manifest.json' }],
        ['script', { id: "unregister-sw" },
            "if('serviceWorker' in navigator) window.addEventListener('load', () => navigator.serviceWorker.register('/yourbaseurl/service-worker.js', { scope: '/yourbaseurl/' }))",
        ]
    ]
  1. add docs/public/service-worker.js with the following,
// force an unregister
// see https://discord.com/channels/325477692906536972/790509637598314527/1032614068164493402
self.addEventListener('install', function (e) {
    self.skipWaiting();
});
self.addEventListener('activate', function (e) {
    self.registration.unregister()
        .then(function () {
            return self.clients.matchAll();
        })
        .then(function (clients) {
            clients.forEach(client => client.navigate(client.url))
        });
});
  1. build and deploy
  2. when you display the new VitePress site, the old service worker will start and then unregister itself. Voilà, your new VitePress site appears.

The one downside I see is each time the service worker is run you get another Application entry. Maybe later you remove this code and assume all of your users have unregistered the old VuePress site?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide | PWA Support - vuepress-theme-hope
Service Worker (SW for short) is mainly used to cache and proxy site content. This plugin will automatically register Service Worker through ...
Read more >
Service Worker not busting cache. · Issue #177 - GitHub
Hello, I've got a weird issue. In devtools, I have cache disabled. When I hit ctrl+r, it still lads a cached old file...
Read more >
Vue PWA not getting new content after refresh - Stack Overflow
What's happening here is that when the updated function gets called in the service worker it goes through and deletes all the caches....
Read more >
Caching in a Vue.js PWA - Axel Hodler - Medium
App is being served from cache by a service worker. [...] Service worker has been registered. New content is downloading. New content is...
Read more >
Service worker delivering old cached files - Vue Forum
Hello, I had a very basic (and buggy) service worker on production environment several months ago. The project was generated with vue-cli ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found