Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can cache.addAll accept wildcard matches?

Is there a way to match wildcard URLs on a serviceWorker's install event?

I'd like to be able to match something like *.bundle.js.

self.addEventListener('install', event => {
  event.waitUntil(
    caches.open(latest.cache).then(cache => {
      return cache.addAll([
        '/',
        '*.bundle.js'
      ])
    })
  )
})
like image 511
Raphael Rafatpanah Avatar asked Feb 18 '17 20:02

Raphael Rafatpanah


People also ask

Which of the following is the parameter of the cache match ()?

match() The match() method of the Cache interface returns a Promise that resolves to the Response associated with the first matching request in the Cache object. If no match is found, the Promise resolves to undefined .

Should you cache the service worker?

Caching unnecessary resources wastes bandwidth and storage space and could cause your app to serve unintended outdated resources. You don't need to cache all the assets at once, you can cache assets many times during the lifecycle of your PWA, such as: On installation of the service worker. After the first page load.

How long does PWA cache last?

A PWA that goes unused for a 'few weeks' (we think it is 2 weeks) the iOS device deletes or purges the stored values. That is unless it has been added to the homescreen. Not exactly the most user friendly policy and definitely not favorable to a business using service workers to provide better user experience.


1 Answers

I don't think that's possible since you're not caching strings or urls, but requests.

There is a thing from Google that might be of use, the sw-precache module. This can generate a service worker through Gulp or the commandline. It works alongside the service worker toolbox.

like image 162
Sorskoot Avatar answered Oct 08 '22 10:10

Sorskoot