FIX: Prefetch

This commit is contained in:
Tony Air 2024-06-22 23:50:53 +02:00
parent 85f9c08cb1
commit 244a0c8629

View File

@ -253,16 +253,17 @@ class DeferredRequirements implements TemplateGlobalProvider
$html .= '<link rel="preload" as="fetch" href="'.$preloadPath.'" />'
.'<script>'
.'window.addEventListener("load-ready",() =>{'
.'window.dispatchEvent(new Event("prefetch-loaded"));console.log("Prefetched before js ready")'
.'});'
.'try{'
."fetch('".$preloadPath."', {method:'GET',credentials:'include',mode:'no-cors'})"
.'.then((r)=>{return r.json()})'
.'.then((d)=>{'
.'window.preloadedData = d;'
.'window.dispatchEvent(new Event("prefetch-loaded"));'
.'console.log("Prefetch is loaded")'
.'console.log("Prefetch is loaded");'
.'window.addEventListener("load-ready",() =>{'
.'window.dispatchEvent(new Event("prefetch-loaded"));'
.'console.log("Prefetched before js ready")'
.'});'
.'})'
.'.catch((e) => {'
.'window.dispatchEvent(new Event("prefetch-loaded"));'