Skip to content

Improve performance of the Category page #40082

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

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@
$width = (int)$block->getWidth();
$height = (int)$block->getHeight();
$paddingBottom = $block->getRatio() * 100;

$globalBlock = $block->getLayout()->getBlock('header');
if ($globalBlock) {
$catImage = $globalBlock->getData('cat_image_counter') ?? 0;
$catImage++;
$globalBlock->setData('cat_image_counter', $catImage);
} else {
$catImage = 10;
}

$isProductPage = ($block->getRequest()->getFullActionName() === 'catalog_product_view');
$isHomePage = ($block->getFullActionName() === 'cms_index_index');
?>
<span class="product-image-container product-image-container-<?= /* @noEscape */ $block->getProductId() ?>">
<span class="product-image-wrapper">
<img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtml($value) ?>"
<?php endforeach; ?>
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
src="<?=$escaper->escapeUrl($block->getImageUrl())?>"
<?php if ($catImage > 1 || $isProductPage || $isHomePage) { ?>
loading="lazy"
fetchpriority="low"
<?php } else { ?>
loading="eager"
fetchpriority="high"
<?php } ?>
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>"/></span>
Expand Down