mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
IMPR: Preload content
This commit is contained in:
parent
f11151338e
commit
6b2f619424
@ -245,8 +245,27 @@ class DeferredRequirements implements TemplateGlobalProvider
|
||||
.WebpackTemplateProvider::resourcesURL('logo.png')
|
||||
.'" />';
|
||||
|
||||
/*$preloadPath = Controller::curr()->Link().'?ajax=1';
|
||||
$html .= '<link rel="preload" as="fetch" href="'.$preloadPath.'" />'."<script>fetch('".$preloadPath."', {method:'GET',credentials:'include',mode:'no-cors'}).then((r)=>{return r.json()}).then((d)=>{window.preloadedData = d})</script>";*/
|
||||
$ctrl = Controller::curr();
|
||||
if ($ctrl) {
|
||||
$preloadPath = $ctrl->Link();
|
||||
$preloadPath = ($preloadPath === '/home/') ? '/' : $preloadPath;
|
||||
$preloadPath = $preloadPath.'?ajax=1&m='.time();
|
||||
|
||||
$html .= '<link rel="preload" as="fetch" href="'.$preloadPath.'" />'
|
||||
.'<script>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")'
|
||||
.'})'
|
||||
.'.catch((e) => {'
|
||||
.'window.dispatchEvent(new Event("prefetch-loaded"));'
|
||||
.'console.warn("Prefetch Error", e)'
|
||||
.'})'
|
||||
.'}catch(e){window.dispatchEvent(new Event("prefetch-loaded"));console.warn("Prefetch Error", e)}</script>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user