admin管理员组

文章数量:1279211

I have a website which was using gatsbyJS (React framework for static sites)

Now I have moved the site to a CMS (WordPress) but because we have used gatsbyJS initially on the same domain, it's showing old cached files that gatsby has built.

we are not able to access the new website on browsers where someone has initially opened the gatsby site, as its just showing the cached files.

From my initial search I came to know following things:

  1. GatsbyJS is optimized for offline access using service workers.
  2. To invalidate the service workers, I need to again server the GatsbyJS static site after adding some script so that when someone visits the site, service workers gets invalidated.
  3. I can't control service workers otherwise.

I can't go back to initial site as that's already been published and people are looking at it but there are many other people who are still seeing the broken gatsby site.

any solution for the above issue?

I have a website which was using gatsbyJS (React framework for static sites)

Now I have moved the site to a CMS (WordPress) but because we have used gatsbyJS initially on the same domain, it's showing old cached files that gatsby has built.

we are not able to access the new website on browsers where someone has initially opened the gatsby site, as its just showing the cached files.

From my initial search I came to know following things:

  1. GatsbyJS is optimized for offline access using service workers.
  2. To invalidate the service workers, I need to again server the GatsbyJS static site after adding some script so that when someone visits the site, service workers gets invalidated.
  3. I can't control service workers otherwise.

I can't go back to initial site as that's already been published and people are looking at it but there are many other people who are still seeing the broken gatsby site.

any solution for the above issue?

Share Improve this question asked Aug 23, 2018 at 17:21 Deepak jhaDeepak jha 3085 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

You could try to add a script to the new site that removes all service workers, if there are any:

<script>
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.getRegistrations().then(function(registrations) {
      for (let registration of registrations) {
        registration.unregister();
      }
    });
  }
</script>

If this is not sufficient in your case, check out self-destroying-sw:

  1. Remove everything about your previous ServiceWorker (registration/uninstallation code, ServiceWorker file)

  2. Create a file with the same name as your previous ServiceWorker and put it in the same place where your previous ServiceWorker was

  3. Put following code into the file:

    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))
        });
    });
    
  4. Deploy your project!

    本文标签: javascriptCan39t clear Gatsby static site cacheStack Overflow