1

I am working with VUE PWA and I am trying to add my own service worker.

checking VUE works the service worker with the sw-precache plugin so I'm trying to import my file so when the build is done I add it and can work my own service worker but it always sends me errors:

A bad HTTP response code (404) was received when fetching the script. service-worker.js:1 Uncaught

(anonymous) @ service-worker.js:1

(index):1 Error during service worker registration: TypeError: Failed to register a ServiceWorker: ServiceWorker script evaluation failed

My file custom-service-worker.js I declared it in src / and I tried too on static folder and on root

And this is the code that I modified in the sw-precache plugin:

// service worker caching
new SWPrecacheWebpackPlugin({
  cacheId: 'offline-gallery',
  filename: 'service-worker.js',
  staticFileGlobs: ['dist/**/*.{js,html,css,png}'],
  runtimeCaching: [
    {
      urlPattern: /^https:\/\/res\.cloudinary\.com\//,
      handler: 'cacheFirst'
    }
  ],
  minify: true,
  stripPrefix: 'dist/',
  importScripts: ['custom-service-worker.js']
})

Does anyone know how to achieve it?

OscarDev
  • 687
  • 6
  • 22

0 Answers0