-
Notifications
You must be signed in to change notification settings - Fork 6
noscript-Support für CSS ergänzt #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Noscript für CSS ergänzt für render-blocking-assets, media="all" als default gestrichen, wegen best-practice
Noscript für CSS ergänzt für render-blocking-assets, media="all" als default gestrichen, wegen best-practice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds <noscript> support for CSS assets to avoid render-blocking and removes the default media="all" to follow best practices for loading CSS.
- Introduces a
noscriptflag ingetLinkTag()to wrap stylesheets in<noscript>tags with preload and onload attributes. - Changes
setCss()to require explicit media values (no default) and to accept the newnoscriptparameter. - Updates
getCss()to pass thenoscriptflag through to the link tag renderer.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/theme_assets_trait.php | Extended getLinkTag() with a noscript parameter and onload logic. |
| lib/theme_assets.php | Modified setCss() and getCss() to remove default media and support noscript. |
Comments suppressed due to low confidence (3)
lib/theme_assets_trait.php:41
- The docblock above
getLinkTag()needs to be updated to include the new@param bool $noscriptso that the purpose and default behavior of this parameter are clear.
private function getLinkTag(string $key, string $file, array $attributes, string $cache_buster = '', bool $noscript = false): string
lib/theme_assets.php:66
- This change is a breaking API update: removing the default
media='all'and adding the$noscriptparameter will affect existing callers. Consider documenting this change clearly or providing a migration path.
public function setCss(string $key, string $data, string $media = '', array $attributes = [], bool $noscript = false): theme_assets
lib/theme_assets.php:66
- Update the docblock for
setCss()to describe the new$noscriptparameter and note that themediaparameter no longer defaults to'all'.
public function setCss(string $key, string $data, string $media = '', array $attributes = [], bool $noscript = false): theme_assets
| $attributes['type'] = $attributes['type'] ?? 'text/css'; | ||
|
|
||
| return '<link'.rex_string::buildAttributes($attributes).' />'.PHP_EOL; | ||
| return '<link'.rex_string::buildAttributes($attributes).$onload.' />'.$noscript_tag.PHP_EOL; |
Copilot
AI
Jul 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider inserting a newline or space before $noscript_tag so that the <noscript> element is rendered on its own line for improved readability of the generated HTML.
| return '<link'.rex_string::buildAttributes($attributes).$onload.' />'.$noscript_tag.PHP_EOL; | |
| return '<link'.rex_string::buildAttributes($attributes).$onload.' />'.PHP_EOL.$noscript_tag.PHP_EOL; |
|
Hi, Allerdings finde ich die Anpassung so noch nicht ideal:
Soweit ich mir das auf die Schnelle anlesen konnte, gibt es ein Best-Practise-Setting, mit dem man das Thema dann standardisiert angehen kann.
|
Noscript für CSS ergänzt für render-blocking-assets,
media="all"als default gestrichen, wegen best-practice.https://developer.chrome.com/docs/lighthouse/performance/render-blocking-resources?hl=de
man kann nun wie folgt css einbinden:
$assets->setCss('plyr', '/assets/addons/plyr/vendor/plyr/dist/plyr.css','', ['rel' => 'preload', 'as' => 'style'], true);daraus wird dann:
<link rel="preload" as="style" href="/assets/addons/plyr/vendor/plyr/dist/plyr.css" type="text/css" onload="this.onload=null;this.rel='stylesheet'" /><noscript><link rel="stylesheet" href="/assets/addons/plyr/vendor/plyr/dist/plyr.css"></noscript>