Skip to content

Commit 2064d34

Browse files
authored
feat: set aspect-ratio within css to reduce CLS
1 parent 392851c commit 2064d34

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

CHANGELOG_de-DE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.1.0
2+
3+
* Set aspect-ratio with inline-css to reserve space of images which reduces Cumulative Layout Shift (CLS)
4+
* Set class `frosh-proc` onto images managed by this plugin, use selector `img.frosh-proc` to set specific css style
5+
* Add usage of variable `src`. Use this to determine an own placeholder image or preload image.
6+
17
# 1.0.28
28

39
* Beschränke Konfiguration auf "Alle Saleschannel"

CHANGELOG_en-GB.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.1.0
2+
3+
* Set aspect-ratio with inline-css to reserve space of images which reduces Cumulative Layout Shift (CLS)
4+
* Set class `frosh-proc` onto images managed by this plugin, use selector `img.frosh-proc` to set specific css style
5+
* Add usage of variable `src`. Use this to determine an own placeholder image or preload image.
6+
17
# 1.0.28
28

39
* Restrict configuration to "All Saleschannels"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"thumbnail"
1212
],
1313
"description": "This plugins allows you to use variable thumbnails, without having them on storage.",
14-
"version": "1.0.28",
14+
"version": "1.1.0",
1515
"type": "shopware-platform-plugin",
1616
"license": "mit",
1717
"authors": [

src/Resources/views/storefront/utilities/thumbnail.html.twig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
{% endif %}
55

66
{% if attributes.class %}
7-
{% set attributes = attributes|merge({'class': 'lazyload ' ~ attributes.class}) %}
7+
{% set attributes = attributes|merge({'class': 'frosh-proc lazyload ' ~ attributes.class}) %}
88
{% else %}
9-
{% set attributes = attributes|merge({'class': 'lazyload'}) %}
9+
{% set attributes = attributes|merge({'class': 'frosh-proc lazyload'}) %}
1010
{% endif %}
1111

1212
{% if attributes.alt is not defined and media.translated.alt is defined %}
@@ -31,16 +31,19 @@
3131

3232
{% set ratio = (metaProportion.width / max(metaProportion.height, 1))|round(3, 'floor') %}
3333

34-
{% if fullWidth %}
35-
{% if ratio >= 1 %}
36-
{% set inlineStyle = "width: 100vw; height: " ~ (100 / ratio)|round(3) ~ "vw" %}
37-
{% else %}
38-
{% set inlineStyle = "width: " ~ (100 * ratio)|round(3)~ "vw; height: 100vw" %}
39-
{% endif %}
34+
{% set inlineStyle = "aspect-ratio:" ~ ratio ~ ";" %}
35+
{% if attributes.style %}
36+
{% set attributes = attributes|merge({'style': inlineStyle ~ attributes.style}) %}
37+
{% else %}
38+
{% set attributes = attributes|merge({'style': inlineStyle}) %}
4039
{% endif %}
4140

4241
{% block thumbnail_utility_img %}
43-
<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
42+
{% if src is not defined %}
43+
{% set src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' %}
44+
{% endif %}
45+
46+
<img src="{{ src }}"
4447
data-src="{{ media.url|frosh_encode_url }}"
4548
{% if srcsetValue %}
4649
data-srcset="{{ srcsetValue }}"
@@ -54,9 +57,6 @@
5457
content="{{ media.url|frosh_encode_url }}"
5558
{% endif %}
5659
{% endfor %}
57-
{% if inlineStyle is defined %}
58-
style="{{ inlineStyle }}"
59-
{% endif %}
6060
/>
6161

6262
{% endblock %}

0 commit comments

Comments
 (0)