Skip to content

Commit

Permalink
bug #6697 Fix asset preloading (fracsi)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.x branch.

Discussion
----------

Fix asset preloading

Fix for #6693

Commits
-------

1a3c3c8 Fix asset preloading
  • Loading branch information
javiereguiluz committed Jan 10, 2025
2 parents 8b52a4d + 1a3c3c8 commit 623f063
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions templates/includes/_css_assets.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #}
{% for css_asset in assets %}
{% if css_asset.preload %}
<link rel="preload" href="{{ ea_call_function_if_exists('preload', asset(css_asset.value, css_asset.packageName), { as: 'style', nopush: css_asset.nopush }) }}"
{% for attr, value in css_asset.htmlAttributes %}{{ attr }}="{{ value|e('html_attr') }}" {% endfor %}>
{% else %}
<link rel="stylesheet" href="{{ asset(css_asset.value, css_asset.packageName) }}"
{% for attr, value in css_asset.htmlAttributes %}{{ attr }}="{{ value|e('html_attr') }}" {% endfor %}>
{% endif %}
{% set href = asset(css_asset.value, css_asset.packageName) %}
<link rel="stylesheet" href="{{ (css_asset.preload ? ea_call_function_if_exists('preload', href, { as: 'style', nopush: css_asset.nopush }))|default(href) }}"
{% for attr, value in css_asset.htmlAttributes %}{{ attr }}="{{ value|e('html_attr') }}" {% endfor %}>
{% endfor %}
10 changes: 3 additions & 7 deletions templates/includes/_js_assets.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #}
{% for js_asset in assets %}
{% if js_asset.preload %}
<link rel="preload" href="{{ ea_call_function_if_exists('preload', asset(js_asset.value, js_asset.packageName), { as: 'script', nopush: js_asset.nopush }) }}"
{% for attr, value in js_asset.htmlAttributes %}{{ attr }}="{{ value|e('html_attr') }}" {% endfor %}>
{% else %}
<script src="{{ asset(js_asset.value, js_asset.packageName) }}" {{ js_asset.async ? 'async' }} {{ js_asset.defer ? 'defer' }}
{% for attr, value in js_asset.htmlAttributes %}{{ attr }}="{{ value|e('html_attr') }}" {% endfor %}></script>
{% endif %}
{% set src = asset(js_asset.value, js_asset.packageName) %}
<script src="{{ js_asset.preload ? ea_call_function_if_exists('preload', src, { as: 'script', nopush: js_asset.nopush })|default(src) }}" {{ js_asset.async ? 'async' }} {{ js_asset.defer ? 'defer' }}
{% for attr, value in js_asset.htmlAttributes %}{{ attr }}="{{ value|e('html_attr') }}" {% endfor %}></script>
{% endfor %}

0 comments on commit 623f063

Please sign in to comment.