oliviertassinari / serviceworker-webpack-plugin

Simplifies creation of a service worker to serve your webpack bundles. :recycle:
https://oliviertassinari.github.io/serviceworker-webpack-plugin/
MIT License
458 stars 76 forks source link

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

Open kontrollanten opened 6 years ago

kontrollanten commented 6 years ago

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?

woutervanvliet commented 6 years ago

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.

kontrollanten commented 6 years ago

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