Skip to content

Commit 2f1578d

Browse files
author
Avaer Kazmer
committed
Add initial precache on sw install
1 parent dd271b5 commit 2f1578d

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

sw.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,49 @@ const _resolveFollowUrl = u => fetch(_rewriteUrlToProxy(u), {
115115
method: 'HEAD',
116116
}).then(res => _rewriteUrlToRaw(res.url));
117117

118-
self.addEventListener('install', event => {
118+
const cacheName = 'proxy';
119+
let cache = null;
120+
self.addEventListener('install', event => event.waitUntil(
121+
122+
(async () => {
119123
// console.log('sw install');
120-
self.skipWaiting();
124+
125+
await caches.delete(cacheName);
126+
cache = await caches.open(cacheName);
127+
128+
await cache.addAll([
129+
'core.js',
130+
'Document.js',
131+
'Event.js',
132+
'GlobalContext.js',
133+
'Graphics.js',
134+
'HelioWebXRPolyfill.js',
135+
'History.js',
136+
'index.js',
137+
'Location.js',
138+
'Navigator.js',
139+
'symbols.js',
140+
'USKeyboardLayout.js',
141+
'utils.js',
142+
'VR.js',
143+
'webxr-polyfill.module.js',
144+
'WindowBase.js',
145+
'Window.js',
146+
'WindowVm.js',
147+
'xr-iframe.js',
148+
'XR.js',
149+
'xr-scene.js',
150+
].map(n => `/src/${n}`));
121151

122152
/* event.waitUntil(
123153
caches.open(PRECACHE)
124154
.then(cache => cache.addAll(PRECACHE_URLS))
125155
.then(self.skipWaiting())
126156
); */
127-
});
157+
})()
158+
159+
));
160+
128161
self.addEventListener('activate', event => {
129162
// console.log('sw activate');
130163
self.clients.claim();

0 commit comments

Comments
 (0)