webpackservice-workeroffline-caching

What is the correct way to remove webpack offline-plugin?


I was assigned to a project where they had a webpack offline-plugin in the past, but now we don't have it and it is completely unnecessary to have it in the project.

It was installed in such way:

new OfflinePlugin({
  updateStrategy: 'changed',
  autoUpdate: 1000 * 60 * 10,
  minify: {
    removeComments: true,
    collapseWhitespace: true,
    removeRedundantAttributes: true,
    useShortDoctype: true,
    removeEmptyAttributes: true,
    removeStyleLinkTypeAttributes: true,
    keepClosingSlash: true,
    minifyJS: true,
    minifyCSS: true,
    minifyURLs: true,
  },
  ServiceWorker: {
    events: true,
    navigateFallbackURL: '/',
  },
})

Now I am struggling to remove the service worker created for the old clients on the production domain, the ones who accessed the website before the offline-plugin was removed, and most importantly it looks like facebook scraper tool gets the old version every time I try to scrape again and it is crucial since I have deployed a new SSR functionality to the production.

What I have tried already:

  1. webpack-remove-serviceworker-plugin

  2. Add the following code to index.html:

    if (window.navigator && navigator.serviceWorker) {
      navigator.serviceWorker.getRegistrations()
        .then(function (registrations) {
          let registrationsLength = registrations.length;
          while(registrationsLength--) {
            registrations[registrationsLength].unregister();
          }
        });
    }
  1. Replace sw.js with the following content:
    self.addEventListener('install', function(e) {
      self.skipWaiting();
    });
    
    self.addEventListener('activate', function () {
      self.registration.unregister().then(function () {
        return self.clients.matchAll();
      }).then(function (clients) {
        clients.forEach((client) => {
          if (client.url && 'navigate' in client) {
            client.navigate(client.url);
          }
        });
      });
    });

None of these have solved the problem for me. Deploying the project on a new server with another domain works fine. Any tips or suggestions for this problem?


Solution

  • I have successfully resolved my issue, it was related to https://stackoverflow.com/a/25039719/1964570

    It turned out that the website was moved to another hosting and we had some ipv6 AAAA DNS records left, which took priority over new ipv4 records, so after removing them (plus still keeping those solutions for removing service worker) and after clearing cache and 2-3 refreshes the website came to normal operation and the facebook scraping was also fixed