Skip to content

Commit 9bd9761

Browse files
authored
Merge pull request #1 from pierreboissinot/feat/asset-mapper-integrity
[AssetMapper] Add integrity hash to modulepreload
2 parents e8c0c50 + 14f65d3 commit 9bd9761

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Symfony/Component/AssetMapper/ImportMap/ImportMapRenderer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function render(string|array $entryPoint, array $attributes = []): string
7878
$integrityMap[$path] = $integrity;
7979
}
8080
if ($preload) {
81-
$modulePreloads[] = $path;
81+
$modulePreloads[] = ['path' => $path, 'integrity' => $integrity];
8282
}
8383
} elseif ($preload) {
8484
$cssLinks[] = $path;
@@ -142,10 +142,13 @@ public function render(string|array $entryPoint, array $attributes = []): string
142142
HTML;
143143
}
144144

145-
foreach ($modulePreloads as $url) {
146-
$url = $this->escapeAttributeValue($url);
145+
foreach ($modulePreloads as $modulePreload) {
146+
$url = $this->escapeAttributeValue($modulePreload['path']);
147+
if ($integrity = $modulePreload['integrity']) {
148+
$integrity = " integrity=\"$integrity\"";
149+
}
147150

148-
$output .= "\n<link rel=\"modulepreload\" href=\"$url\">";
151+
$output .= "\n<link rel=\"modulepreload\" href=\"$url\"$integrity>";
149152
}
150153

151154
if (\count($entryPoint) > 0) {

0 commit comments

Comments
 (0)