IMPR: Preload

This commit is contained in:
Tony Air 2024-06-21 22:16:04 +02:00
parent df4cefa29d
commit fd72eb62e7

View File

@ -201,10 +201,10 @@ class DeferredRequirements implements TemplateGlobalProvider
private static function getPreloadLine(string $url, string | null $as = null, string | null $type = null) private static function getPreloadLine(string $url, string | null $as = null, string | null $type = null)
{ {
$crossorigin = strpos('//', $url) ? ' crossorigin ' : ''; $crossorigin = '';// strpos('//', $url) ? ' crossorigin="anonymous" ' : '';
$type = $type ?: ' type="'.$type.'" '; $type = $type ? ' type="'.$type.'" ' : '';
return '<link rel="preload" href="'.$url.'" as="'.$as.'"'.$type.$crossorigin.'/>'; return '<link rel="preload" href="'.$url.'" as="'.$as.'" '.$type.$crossorigin.'/>';
} }
public static function Preloads(): string public static function Preloads(): string
@ -241,6 +241,9 @@ class DeferredRequirements implements TemplateGlobalProvider
} }
unset($fonts, $font); unset($fonts, $font);
$preloadPath = Controller::curr()->Link().'?ajax=1';
$html .= '<link rel="preload" as="fetch" href="'.$preloadPath.'" />'."<script>fetch('".$preloadPath."', {method:'GET',credentials:'include',mode:'cors'}).then((r)=>{return r.json()}).then((d)=>{window.preloadedData = d})</script>";
return $html; return $html;
} }