const cacheName = 'v1';

const cacheAssets = [
  '/',
  '/index.html',
  '/style.css',
  // 可以添加其他需要缓存的资源路径
];

self.addEventListener('install', e => {
  e.waitUntil(
    caches.open(cacheName).then(cache => {
      console.log('Caching files...');
      return cache.addAll(cacheAssets);
    })
  );
});

self.addEventListener('fetch', e => {
  e.respondWith(
    fetch(e.request).catch(() => caches.match(e.request))
  );
});
