← All code files

sw.js

Bare-bones service worker: precache the shell and serve cache-first.

const CACHE = 'app-v1';
const ASSETS = ['/', '/index.html', '/styles.css', '/app.js'];

self.addEventListener('install', (e) => {
  e.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS)));
});

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

About this tool

Bare-bones service worker: precache the shell and serve cache-first.

Ready-to-use sw.js — view the content, copy it, or download it with the correct filename. Free and 100% in your browser.