Cache the page-owned app response before starting the worker

This commit is contained in:
Jonathan Sykes
2026-10-08 09:04:20 +08:00
parent e7a7cdc6b9
commit a86fa1cebe
16 changed files with 186 additions and 17 deletions

View File

@@ -122,6 +122,19 @@
for (const type of ['pointerenter', 'focus', 'touchstart']) element.addEventListener(type, () => load(name).catch(() => {}), { once: true, passive: true });
},
};
// Own this response once. Classic-script and fetch preloads do not share
// their cached bodies in WebKit; the later bootstrap consumes this promise.
if(manifest.appCache && root.crypto?.subtle) {
api.appResponse=(async()=>{
const key=url('/app.js');
try {
const cache=await root.caches?.open('ytplayer-assets'), held=await cache?.match(key);
if(held?.headers.get('X-Asset-Hash')===manifest.files['/app.js']?.h && held)return held;
} catch {}
return root.fetch(key,{credentials:'same-origin'});
})();
api.appResponse.catch(()=>{});
}
root.Lazy = api;
root.navigator.serviceWorker?.addEventListener('message',event=>{
if(event.data?.type==='ASSET_LAYOUT_REQUEST') event.source?.postMessage({type:'LAYOUT',value:api.layout});