Skip to content

Commit ad24cb8

Browse files
committed
MC-23383: Introduce image lazy loading mechanism
1 parent 4e085c7 commit ad24cb8

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

app/code/Magento/Catalog/etc/view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
99
<vars module="Magento_Catalog">
1010
<var name="product_image_white_borders">1</var>
11+
<var name="enable_lazy_loading_for_images_without_borders">0</var> <!-- variable to enable lazy loading for catalog product images without borders -->
1112
</vars>
1213
</view>

app/code/Magento/Catalog/view/frontend/templates/product/image.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/** @var $block \Magento\Catalog\Block\Product\Image */
99
/** @var $escaper \Magento\Framework\Escaper */
1010
?>
11-
11+
<!--deprecated template as image_with_borders is a primary one-->
1212
<img class="photo image <?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
1313
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
1414
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>"

app/code/Magento/Catalog/view/frontend/templates/product/image_with_borders.phtml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<?php
88
/** @var $block \Magento\Catalog\Block\Product\Image */
99
/** @var $escaper \Magento\Framework\Escaper */
10+
$borders = (bool)$block->getVar('product_image_white_borders', 'Magento_Catalog');
11+
$enableLazyLoadingWithoutBorders = (bool)$block->getVar('enable_lazy_loading_for_images_without_borders', 'Magento_Catalog');
1012
?>
1113

1214
<span class="product-image-container"
@@ -19,7 +21,13 @@
1921
<?php endforeach; ?>
2022
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
2123
loading="lazy"
22-
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
23-
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
24+
<!-- Enable lazy loading for images with borders and if variable enable_lazy_loading_for_images_without_borders in view.xml is enabled -->
25+
<?php if ($borders || $enableLazyLoadingWithoutBorders) :?>
26+
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
27+
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
28+
<?php else :?>
29+
max-width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
30+
max-height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
31+
<?php endif; ?>
2432
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>"/></span>
2533
</span>

app/code/Magento/Theme/etc/adminhtml/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<system>
1010
<section id="dev" translate="label" type="text" sortOrder="920" showInDefault="1" showInWebsite="1" showInStore="1">
1111
<group id="js">
12-
<field id="move_script_to_bottom" translate="label" type="select" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
12+
<field id="move_script_to_bottom" translate="label" type="select" sortOrder="25" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
1313
<label>Move JS code to the bottom of the page</label>
1414
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1515
</field>
1616
</group>
1717
<group id="css">
18-
<field id="use_css_critical_path" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
18+
<field id="use_css_critical_path" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
1919
<label>Use CSS critical path</label>
2020
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2121
<comment>

app/code/Magento/Theme/view/frontend/templates/html/header/criticalCss.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
<style type="text/css" data-type="criticalCss">
1414
<?= /* @noEscape */ $criticalCssViewModel->getCriticalCssData() ?>
15-
</style>
15+
</style>

0 commit comments

Comments
 (0)