← 모든 코드 파일

sw.js

기본 service worker: 셸을 프리캐시하고 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)));
});

이 도구에 대해

기본 service worker: 셸을 프리캐시하고 cache-first로 제공.

바로 사용할 수 있는 sw.js — 내용을 보고 복사하거나 올바른 파일명으로 다운로드하세요. 무료, 100% 브라우저에서.