diff --git a/lib/theme_assets.php b/lib/theme_assets.php
index c68b477..c6f3ab1 100644
--- a/lib/theme_assets.php
+++ b/lib/theme_assets.php
@@ -63,13 +63,19 @@ public function setCacheBuster(string $cache_buster): theme_assets
return $this;
}
- public function setCss(string $key, string $data, string $media = 'all', array $attributes = []): theme_assets
+ public function setCss(string $key, string $data, string $media = '', array $attributes = [], bool $noscript = false): theme_assets
{
- $attributes['media'] = $media;
+ // If the media attribute is not set, do not default to 'all', because it is considered render-blocking
+ // Even an empty media="" can be render-blocking, so we only set it if a media type is given
+ // https://developer.chrome.com/docs/lighthouse/performance/render-blocking-resources?hl=de
+ if($media !== '') {
+ $attributes['media'] = $media;
+ }
$this->css[$key] = [
'data' => $data,
'attributes' => $attributes,
+ 'noscript' => $noscript,
];
return $this;
@@ -163,7 +169,7 @@ public function getCss(): string
if (!$return) {
foreach ($this->css as $css_key => $css) {
- $return .= $this->getLinkTag($this->id.'--'.$css_key, $css['data'], $css['attributes'], $this->cache_buster);
+ $return .= $this->getLinkTag($this->id.'--'.$css_key, $css['data'], $css['attributes'], $this->cache_buster, $css['noscript'] ?? false);
}
}
diff --git a/lib/theme_assets_trait.php b/lib/theme_assets_trait.php
index 9979f94..0cfdfd3 100644
--- a/lib/theme_assets_trait.php
+++ b/lib/theme_assets_trait.php
@@ -38,18 +38,22 @@ private function getScriptTag(string $key, string $file, array $attributes, stri
*
* @return string
*/
- private function getLinkTag(string $key, string $file, array $attributes, string $cache_buster = ''): string
+ private function getLinkTag(string $key, string $file, array $attributes, string $cache_buster = '', bool $noscript = false): string
{
if ($this->isAdmin()) {
$attributes['data-key'] = 'style--'.$key;
}
-
+ $noscript_tag = $noscript ? '' : '';
+ $onload = '';
+ if($noscript) {
+ $onload = ' onload="this.onload=null;this.rel=\'stylesheet\'"'; // rex_string::buildAttributes() bypass wegen Sanitizer der Hochkommata
+ }
$attributes['href'] = $this->stripDots($file).$this->getCacheBuster($file, $cache_buster);
$attributes['rel'] = $attributes['rel'] ?? 'stylesheet';
$attributes['type'] = $attributes['type'] ?? 'text/css';
- return ''.PHP_EOL;
+ return ''.$noscript_tag.PHP_EOL;
}
/**