serviceworker-webpack-plugin icon indicating copy to clipboard operation
serviceworker-webpack-plugin copied to clipboard

Example: Fallback to './' upon navigate mode?

Open kontrollanten opened this issue 6 years ago • 2 comments

Thank's for a great example to getting started using service workers. I just got a question regarding the following part:

      .catch(() => {
        // User is landing on our page.
        if (event.request.mode === 'navigate') {
          return global.caches.match('./')
        }

        return null
      })

Why do we fall back to global.caches.match('/') upon navigate? What is the "expected" scenario that this will happen? If we have / cached, it will be returned immediately, or am I missing something?

kontrollanten avatar Mar 16 '18 17:03 kontrollanten

We'll look into updating the example with perhaps some better defaults.

What I tend to do fall back on some fallback page, for example "/offline.html" and ensure that to be in the cache.

woutervanvliet avatar Mar 21 '18 10:03 woutervanvliet

Ah, I see. I was too much into SPA thinking. Then it makes sense. Thanks for your answer!

kontrollanten avatar Mar 21 '18 11:03 kontrollanten