← すべてのファイル

sw.js

最小限のservice worker:シェルをプリキャッシュしてキャッシュ優先で配信。

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)));
});

このツールについて

最小限のservice worker:シェルをプリキャッシュしてキャッシュ優先で配信。

すぐ使える sw.js — 内容を表示・コピー、または正しいファイル名でダウンロード。無料・100%ブラウザ内。