github.com/pbberlin/go-pwa@v0.0.0-20220328105622-7c26e0ca1ab8/app-bucket/js-service-worker/promise-all-map-example.js (about) 1 const url = 1; 2 3 Promise.all( 4 ['/styles.css', '/script.js'].map( 5 async url => { 6 return fetch(url) 7 .then( 8 (response) => { 9 if (!response.ok) throw Error('Not ok'); 10 return cache.put(url, response); 11 } 12 ); 13 } 14 ) // map 15 ); // all 16 17 18 19 // my fcSttc and fcReval amount to the same thing: 20 // https://web.dev/offline-cookbook/#stale-while-revalidate 21 const fc1 = async (evt,cch) => { 22 return cch.match(evt.request) 23 .then( 24 (rspCch) => { 25 var promNet = fetch(evt.request) 26 .then( 27 function (netRsp) { 28 cch.put(evt.request, netRsp.clone()); 29 return netRsp; 30 } 31 ); 32 return rspCch || promNet; 33 } 34 ); 35 }; 36 37 let event = null; 38 self.addEventListener('fetch', (event) => { 39 event.respondWith( 40 caches.open('mysite-dynamic').then( fc1(event, cache) ) 41 ); 42 });