Skip to content

Commit

Permalink
use 'rel=modulepreload' for .mjs files (EcmaScript modules)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Dietrich committed Apr 30, 2024
1 parent a928762 commit 7ccad68
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Classes/Http/ResourcePusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 7ccad68

Please sign in to comment.