소스 검색

Editor: Improved ServiceWorker logging.

Mr.doob 5 년 전
부모
커밋
24aa2a29fa
1개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 20 3
      editor/sw.js

+ 20 - 3
editor/sw.js

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