How to cache bust sw-toolbox?

后端 未结 2 1744
时光取名叫无心
时光取名叫无心 2021-01-18 15:14

I have been toying around with service workers and sw-toolbox. Both are great methods but seems to have their weaknesses.

My project started out using Google\'s met

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-18 15:31

    I don't know if sw_toolbox has cache busting built in. Typically when you change the service worker and need to purge the previous version's cache you should do that with in the activate event handler.

    The best practice here is to name your caches with the sw version number included. Here is some example code from an online course I have on service worker caching that might get you started:

    self.addEventListener("activate", event => {
    
    console.log("service worker activated");
    
    //on activate
    event.waitUntil(caches.keys()
        .then(function (cacheNames) {
    
            cacheNames.forEach(function (value) {
    
                if (value.indexOf(config.version) < 0) {
    
                    caches.delete(value);
    
                }
    
            });
    
            return;
    
        })
    );
    

    });

提交回复
热议问题