Skip to content

Allow cached resources #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bahmutov opened this issue Oct 6, 2016 · 0 comments
Closed

Allow cached resources #11

bahmutov opened this issue Oct 6, 2016 · 0 comments

Comments

@bahmutov
Copy link
Owner

bahmutov commented Oct 6, 2016

Like JS and CSS. Probably pass a list into the call to setup.
The fetch event should become something like

const urls = ['/', 'app.css']
  self.addEventListener('install', (event) => {
    event.waitUntil(
      caches.open('demo').then((cache) => cache.addAll(urls))
    )
  })

  self.addEventListener('fetch', function (event) {
    const parsedUrl = url.parse(event.request.url)
    console.log(myName, 'fetching page', parsedUrl.path)

    if (isJsRequest(parsedUrl.path) || isCssRequest(parsedUrl.path)) {
      event.respondWith(
        caches.open('demo').then(cache => {
          return cache.match(event.request)
            .then(cached => {
              if (cached) {
                return cached
              }
              return Promise.reject()
            })
          .catch(err => fetch(event.request))
        })
      )
      return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant