|
@@ -179,10 +179,19 @@ const staticAssets = [
|
|
|
|
|
|
];
|
|
];
|
|
|
|
|
|
-self.addEventListener( 'install', async function ( event ) {
|
|
|
|
|
|
+self.addEventListener( 'install', async function () {
|
|
|
|
|
|
const cache = await caches.open( 'threejs-editor' );
|
|
const cache = await caches.open( 'threejs-editor' );
|
|
- cache.addAll( staticAssets );
|
|
|
|
|
|
+
|
|
|
|
+ staticAssets.forEach( function ( asset ) {
|
|
|
|
+
|
|
|
|
+ cache.add( asset ).catch( function () {
|
|
|
|
+
|
|
|
|
+ console.error( '[SW] Cound\'t cache:', asset );
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
@@ -196,6 +205,14 @@ self.addEventListener( 'fetch', async function ( event ) {
|
|
async function cacheFirst( request ) {
|
|
async function cacheFirst( request ) {
|
|
|
|
|
|
const cachedResponse = await caches.match( request );
|
|
const cachedResponse = await caches.match( request );
|
|
- return cachedResponse || fetch( request );
|
|
|
|
|
|
+
|
|
|
|
+ if ( cachedResponse === undefined ) {
|
|
|
|
+
|
|
|
|
+ console.error( '[SW] Not cached:', request.url );
|
|
|
|
+ return fetch( request );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cachedResponse;
|
|
|
|
|
|
}
|
|
}
|