diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-01-14 12:20:20 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-01-14 12:20:20 +0800 |
| commit | e4adb5dbc6952c4ddbb031e4999f4181f2de8b03 (patch) | |
| tree | 8aade721eb33966baed6f1d45edee24e865973db /public | |
| parent | 1bb4b2d77a1f402ad61cf0058e94d2bf1a7e1703 (diff) | |
un-comment codes
Diffstat (limited to 'public')
| -rw-r--r-- | public/js/main.js | 11 | ||||
| -rw-r--r-- | public/sw.js | 50 |
2 files changed, 36 insertions, 25 deletions
diff --git a/public/js/main.js b/public/js/main.js new file mode 100644 index 00000000..80d6bcce --- /dev/null +++ b/public/js/main.js @@ -0,0 +1,11 @@ +"use strict"; + +if ('serviceWorker' in navigator) { + window.addEventListener('load', function () { + navigator.serviceWorker.register('/sw.js').then(function (reg) { + console.log('sw.js Registered', reg); + }).catch(function (err) { + console.log('sw.js failed: ', err); + }); + }); +}
\ No newline at end of file diff --git a/public/sw.js b/public/sw.js index e6a263d1..61bac97c 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,27 +1,27 @@ -// const cacheName = 'cache-v1' -// const resourceToPrecache = [ -// '/', -// 'index.html', -// '/css/', -// '/js/', -// '/pages/', -// '/fonts/' -// ] +const cacheName = 'cache-v1' +const resourceToPrecache = [ + '/', + 'index.html', + '/css/', + '/js/', + '/pages/', + '/fonts/' +] -// self.addEventListener('install', event => { -// console.log("Service Worker: Installed"); -// event.waitUntil( -// caches.open(cacheName) -// .then(cache => { -// return cache.addAll(resourceToPrecache) -// }) -// ) -// }) +self.addEventListener('install', event => { + console.log("Service Worker: Installed"); + event.waitUntil( + caches.open(cacheName) + .then(cache => { + return cache.addAll(resourceToPrecache) + }) + ) +}) -// self.addEventListener('fetch', event => { -// event.respondWith(catches.match(event.request) -// .then(cachedResponse => { -// return cachedResponse || fetch(event.request); -// }) -// ); -// });
\ No newline at end of file +self.addEventListener('fetch', event => { + event.respondWith(catches.match(event.request) + .then(cachedResponse => { + return cachedResponse || fetch(event.request); + }) + ); +});
\ No newline at end of file |
