BBVAEngineering / ember-cli-workbox

Offline caching as a progressive enhancement using service workers
MIT License
20 stars 10 forks source link

Service worker tries to register on the parent route despite being configured as an absolute path. #100

Closed wopian closed 3 years ago

wopian commented 3 years ago

I have ember-cli-workbox@1.2.0 setup with the following configuration:

module.exports = function(defaults) {
  const app = new EmberApp(defaults, {
    'ember-cli-workbox': {
      enabled: true,
      autoRegister: true,
      debug: environment !== 'production'
    },

    workbox: {
      swDest: '/sw.js',
      skipWaiting: true,
      clientsClaim: true,
      sourcemap: false,
      navigateFallback: '/index.html',
      navigationPreload: false
    }
  }
}

However, when run the service worker is successfully registered and subscribed to on /, but for every other route it attempts to find the service worker at the parent route. For example:

* This leaves behind a redundant service worker registered to the parent route (e.g /users on /users/wopian) and an error in console that the service worker registration encountered a HTTP 400 response. This adds up to a lot of redundant service workers with either multiple refreshes or landing on different routes.

With swDest set to /sw.js, an absolute path, I would have expected all routes to register a service worker to / (e,g /users/wopian/library registers /sw-[hash].js.

The built service worker is only located at /sw-[hash].js.

Edit: The default swDest of ./sw.js tries to request the same service worker paths as /sw.js

wopian commented 3 years ago

Looks like this was resolved in v2.0.0, thank you! 🎉