Skip to content

Commit

Permalink
Merge pull request #29 from bavarianbytes/master
Browse files Browse the repository at this point in the history
use 'rel=modulepreload' for .mjs files (EcmaScript modules)
  • Loading branch information
bmack authored May 2, 2024
2 parents a928762 + 7ccad68 commit fc488c8
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 fc488c8

Please sign in to comment.