Skip to content

Commit 5b8fea3

Browse files
authored
Bugfix/preloaded resource not used (#2207)
* Add possibility to remove the tag from assets * Preloaded files cannot have request parameters; remove tag * Change order: preloading must be done after referencing the resource (in the stylesheet in this case) * Add comment * coding style * phpcs
1 parent 28c3f6e commit 5b8fea3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/SimpleSAML/XHTML/Template.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ class_exists($controller)
170170
* the original file.
171171
* @param string $asset
172172
* @param string|null $module
173+
* @param bool $tag
173174
* @return string
174175
*/
175-
public function asset(string $asset, string $module = null): string
176+
public function asset(string $asset, string $module = null, bool $tag = true): string
176177
{
177178
$baseDir = $this->configuration->getBaseDir();
178179
$basePath = $this->configuration->getBasePath();
@@ -191,6 +192,12 @@ public function asset(string $asset, string $module = null): string
191192
// don't be too harsh if an asset is missing, just pretend it's there...
192193
return $path;
193194
}
195+
196+
if ($tag === false) {
197+
// The asset is requested without a tag
198+
return $path;
199+
}
200+
194201
$file = new File($file);
195202

196203
$tag = $this->configuration->getVersion();

templates/base.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
<meta name="viewport" content="initial-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
88
<title>{{ pagetitle }}</title>
9-
<link rel="preload" href="{{ asset('fonts/fa-solid-900.woff2') }}" as="font" type="font/woff2" crossorigin>
109
<link rel="stylesheet" href="{{ asset("css/stylesheet.css") }}">
1110
<link rel="icon" href="{{ asset("icons/favicon.ico") }}">
11+
{# Preloading must be done after referencing the resource #}
12+
<link rel="preload" href="{{ asset('fonts/fa-solid-900.woff2', null, false) }}" as="font" type="font/woff2" crossorigin>
1213
<meta name="robots" content="noindex, nofollow">
1314
{{ include('_head.twig', ignore_missing = true) }}
1415
{% block preload %}{% endblock %}

0 commit comments

Comments
 (0)