在javascript网络应用程序的Service Worker中使用Workbox。想要清除所有内容的整个工作箱/应用程序缓存...基本上返回到与第一次将应用程序加载到浏览器之前的状态尽可能相似的状态,然后可能通过window.location.href刷新='/'。
在Google上进行谷歌搜索,发现了各种清除缓存中各种内容的方法。我还无法找出一种简单的方法来“清除所有内容并重新开始”。
我在sw.js的服务器代码中尝试了此操作:
var logit = true;
if (logit) console.log('Service Worker Starting Up for Caching... Hello from sw.js');
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js');
if (workbox) {
if (logit) console.log(`Yay! Workbox is loaded `);
} else {
if (logit) console.log(`Boo! Workbox didn't load `);
}
workbox.routing.registerRoute(
// Cache image files
/.*\.(?:mp3|flac|png|gif|jpg|jpeg|svg|mp4)/,
// Use the cache if it's available
workbox.strategies.cacheFirst({
// Use a custom cache name
cacheName: 'asset-cache',
plugins: [
new workbox.expiration.Plugin({
// Cache only 20 images
maxEntries: 20,
// Cache for a maximum of …Run Code Online (Sandbox Code Playgroud)