From 7ccad68ae940ca485ea363f4268df975420cb29d Mon Sep 17 00:00:00 2001 From: Christoph Dietrich Date: Tue, 30 Apr 2024 13:21:30 +0200 Subject: [PATCH] use 'rel=modulepreload' for .mjs files (EcmaScript modules) --- Classes/Http/ResourcePusher.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Classes/Http/ResourcePusher.php b/Classes/Http/ResourcePusher.php index f72b010..3cbbe69 100644 --- a/Classes/Http/ResourcePusher.php +++ b/Classes/Http/ResourcePusher.php @@ -49,6 +49,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface protected function addPreloadHeaderToResponse(ResponseInterface $response, string $uri, string $type): ResponseInterface { - return $response->withAddedHeader('Link', '<' . htmlspecialchars(PathUtility::getAbsoluteWebPath($uri)) . '>; rel=preload; as=' . $type); + if(str_contains($uri, '.mjs')) { + return $response->withAddedHeader('Link', '<' . htmlspecialchars(PathUtility::getAbsoluteWebPath($uri)) . '>; rel=modulepreload; as=' . $type); + } else { + return $response->withAddedHeader('Link', '<' . htmlspecialchars(PathUtility::getAbsoluteWebPath($uri)) . '>; rel=preload; as=' . $type); + } } }