← Back
const CACHE = 'wb-v3-20260523';
const ASSETS = [
  '/weather-bot/',
  '/weather-bot/static/css/style.css',
  '/weather-bot/static/js/app.js',
];

self.addEventListener('install', e => {
  e.waitUntil(
    caches.open(CACHE).then(c =>
      Promise.all(ASSETS.map(url =>
        fetch(url, { cache: 'no-store' }).then(res => c.put(url, res))
      ))
    )
  );
  self.skipWaiting();
});

self.addEventListener('activate', e => {
  e.waitUntil(
    caches.keys().then(keys =>
      Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
    )
  );
  self.clients.claim();
});

self.addEventListener('fetch', e => {
  // API calls — network only (no cache)
  if (e.request.url.includes('/api/')) return;
  // Static assets — network first, fall back to cache
  e.respondWith(
    fetch(e.request)
      .then(r => {
        const clone = r.clone();
        caches.open(CACHE).then(c => c.put(e.request, clone));
        return r;
      })
      .catch(() => caches.match(e.request))
  );
});

📜 Git History

8fca132chore: initial commit — version control setup5 weeks ago
Show last diff
Loading...