Skip to content

Commit

Permalink
Editor: Use networkFirst in sw.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Apr 7, 2021
1 parent 5069d47 commit 0b608ec
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions editor/sw.js
@@ -1,4 +1,4 @@
const cacheName = 'threejs-editor-r127';
const cacheName = 'threejs-editor';

const assets = [
'./',
Expand Down Expand Up @@ -234,10 +234,29 @@ self.addEventListener( 'install', async function () {
self.addEventListener( 'fetch', async function ( event ) {

const request = event.request;
event.respondWith( cacheFirst( request ) );
event.respondWith( networkFirst( request ) );

} );

async function networkFirst( request ) {

return fetch( request ).catch( async function () {

const cachedResponse = await caches.match( request );

if ( cachedResponse === undefined ) {

console.warn( '[SW] Not cached:', request.url );

}

return cachedResponse;

} );

}

/*
async function cacheFirst( request ) {
const cachedResponse = await caches.match( request );
Expand All @@ -252,3 +271,4 @@ async function cacheFirst( request ) {
return cachedResponse;
}
*/

0 comments on commit 0b608ec

Please sign in to comment.