SlideShare uma empresa Scribd logo
1 de 22
Images & PWA in
Magento
© Rrap Software Pvt Ltd
Pradip Shah,
Founder, luroConnect
© Rrap Software Pvt Ltd
© Rrap Software Pvt Ltd
eCommerce trends
Mobile
Image quality
Webp
Magento direction
No support for media queries
No support for pixel ratio
No support for webp
Whine, Whine!
© Rrap Software Pvt Ltd
Problems of Magento Images
• One solution is not suitable to all – code is not flexible
• Ignores mobile completely
• Mobile displays are better than desktop
• Iphone X has 3x retina display
• Most android phones are 2x
• Major difference in image quality
• Chrome & Firefox support webp – not Magento
• Ignores custom transformations you may need
© Rrap Software Pvt Ltd
img srcset & picture
Source : http://w3c.github.io
© Rrap Software Pvt Ltd
Magento 2 & image code
module-catalog/Block/Product/AbstractProduct.php
public function getImage($product, $imageId, $attributes = []){
return $this->imageBuilder->create($product, $imageId, $attributes);
templates/product/list.phtml
$productImage = $block->getImage($_product, $image);
module-catalog/Block/Product/ImageBuilder.php
public function create(Product $product = null, string $imageId = null, array $attributes = null){
$product = $product ?? $this->product;
$imageId = $imageId ?? $this->imageId;
$attributes = $attributes ?? $this->attributes;
return $this->imageFactory->create($product, $imageId, $attributes);
module-catalog/Block/Product/ImageFactory.php
$data = [ 'data' => [
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
'image_url' => $imageAsset->getUrl(), 'width' => $imageMiscParams['image_width’],
…
'product_id' => $product->getId()
],
];
return $this->objectManager->create(ImageBlock::class, $data);
© Rrap Software Pvt Ltd
Magento does not support devicepixelratio
<theme>/templates/product/image_with_borders.phtml :
<span class="product-image-container"
style="width:<?= /* @escapeNotVerified */ $block->getWidth() ?>px;">
<span class="product-image-wrapper"
style="padding-bottom: <?= /* @escapeNotVerified */ ($block->getRatio() * 100) ?>%;">
<img class="product-image-photo"
<?= /* @escapeNotVerified */ $block->getCustomAttributes() ?>
src="<?= /* @escapeNotVerified */ $block->getImageUrl() ?>"
max-width="<?= /* @escapeNotVerified */ $block->getWidth() ?>"
max-height="<?= /* @escapeNotVerified */ $block->getHeight() ?>"
alt="<?= /* @escapeNotVerified */ $block->stripTags($block->getLabel(), null, true) ?>"/></span>
</span>
Guess what?
You are hosed!
The lowest element is generating a product-container
© Rrap Software Pvt Ltd
list.phtml …
<div class="product-item-info" data-container="product-<?= /* @escapeNotVerified */ $viewMode ?>">
<?php
$productImage = $block->getImage($_product, $imageDisplayArea);
…
<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
class="product photo product-item-photo" tabindex="-1">
<?= $productImage->toHtml() ?>
</a>
© Rrap Software Pvt Ltd
<div class="product-item-info" data-container="product-<?= /* @escapeNotVerified */ $viewMode ?>">
<?php
$productImage_dt = $block->getImage($_product, $imageDisplayArea);
$productImage_dt_webp = $block->getImage($_product, $imageDisplayArea . “_webp”);
$productImage_pd = $block->getImage($_product, $imageDisplayArea . “_pad”);
$productImage_mo_2x = $block->getImage($_product, $imageDisplayArea . “_mo_2x”);
$productImage_mo_webp_2x = $block->getImage($_product, $imageDisplayArea . “_mo_webp_2x”);
…
<a href="<?= $_product->getProductUrl() ?>"
<span class="product-image-container">
<span class="product-image-wrapper“>
<picture class="product-image-photo“>
<source media="(max-width: 415px)"
srcset="<?php echo $productImage_mo->toHTML(); ?>,
<?php echo $productImage_mo_2x->toHTML();?> 2x" type="image/jpeg">
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="="<?php echo $productImage->toHTML(); ?>
</picture>
</span>
</a> <theme>/templates/product/image_only.phtml :
<?php $block->getImageUrl() ?>
<div class="product-item-info" data-container="product-<?= /* @escapeNotVerified */ $viewMode ?>">
<?php
$productImage_small = $product->getMediaConfig()->getMediaUrl($product->getData(‘small’);
$productImage_large = $product->getMediaConfig()->getMediaUrl($product->getData(‘large’);
…
<a href="<?= $_product->getProductUrl() ?>"
<span class="product-image-container">
<span class="product-image-wrapper“>
<picture class="product-image-photo“>
<source media="(max-width: 415px)"
srcset="<?php echo $productImage_small.’?w=180&h=180&o=webp’?>,
<?php echo $productImage_large.’?w=360&h=360&o=webp’?> 2x" type="image/webp">
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="="<?php echo $productImage->toHTML(); ?>
</picture>
</span>
</a>
What we do
© Rrap Software Pvt Ltd
Synchronous image generation
• Traditionally Magento generated images when the frontend would
load – category page with 32 items
• Many CDN based image generation is synchronous
• i.e. while the image is being fetched it is being converted
• However, due to HTTP/2, the requests will go out in parallel
Browser
php
img1 img2 img3
Request Response
© Rrap Software Pvt Ltd
Magento 2.3 and image code
Asynchronous generation of images
module-catalog/Observer/ImageResizeAfterProductSave.php
if (!(bool) $product->getId()) {
foreach ($product->getMediaGalleryImages() as $image) {
$this->imageResize->resizeFromImageName($image->getFile());
}
} else {
module-media-storage/Service/ImageResize.php
public function resizeFromImageName(string $originalImageName) {
…
foreach ($this->getViewImages($this->getThemesInUse()) as $viewImage) {
$this->resize($viewImage, $originalImagePath, $originalImageName);
private function resize(array $viewImage, string $originalImagePath, string $originalImageName)
{
$imageParams = $this->paramsBuilder->build($viewImage);
$image = $this->makeImage($originalImagePath, $imageParams);
…
$image->resize($imageParams['image_width'], $imageParams['image_height’]);
…
$image->save($imageAsset->getPath());
Guess what?
each image will have many variations use them or not!
Fix the view.xml in your themes now.
© Rrap Software Pvt Ltd
PWA and images
• Fetching a correctly sized image
You should get a higher resolution image if you are on a high pixel
density device. A good rule of thumb is to multiply the size of the
image you display by the pixel ratio.
var image = getImage({
width: PixelRatio.getPixelSizeForLayoutSize(200),
height: PixelRatio.getPixelSizeForLayoutSize(100),
});
<Image source={image} style={{width: 200, height: 100}} />
https://facebook.github.io/react-native/docs/0.8/pixelratio
© Rrap Software Pvt Ltd
PWA has choices of
© Rrap Software Pvt Ltd
© Rrap Software Pvt Ltd
https://headless.page/
© Rrap Software Pvt Ltd
PWA has
potential but
don’t use
Magento for
images
© Rrap Software Pvt Ltd
www.hartsofstur.com
https://www.hartsofstur.com/api
/catalog/products/57
© Rrap Software Pvt Ltd
Same image to all devices
© Rrap Software Pvt Ltd
Other image services
• Imagekit
• Great Indian Bootstrapped SaaS story
• Piggyback on a paid cloudflare account
• Cloudflare does webp conversion
• Imagekit backend offers image optimization
• Issue : Not application aware, conversion is synchronous, cf is distributed
• Question : Do they store or just convert (cf is distributed remember)
• Fastly
• Magento cloud partner – application aware
• CDN with Varnish on edge – distributed varnish
• Image optimization is synchronous
© Rrap Software Pvt Ltd
Resources
• https://medium.com/@bjoern.meyer/pwa-ecommerce-solutions-
compared-83bb498433e9
• https://headless.page/
© Rrap Software Pvt Ltd
https://www.luroConnect.com/
Where to find us
https://www.luroConnect.com/
info@luroConnect.com
@luroconnect

Mais conteúdo relacionado

Mais procurados

Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
Ivan Chepurnyi
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
Remy Sharp
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
Edna17
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
Andrelma
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
emedomimgues
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
Michelangelo van Dam
 

Mais procurados (20)

Gae
GaeGae
Gae
 
Make More Money With Advanced Custom Fields - WordCampYYC 2015
Make More Money With Advanced Custom Fields - WordCampYYC 2015Make More Money With Advanced Custom Fields - WordCampYYC 2015
Make More Money With Advanced Custom Fields - WordCampYYC 2015
 
Stripes Framework
Stripes FrameworkStripes Framework
Stripes Framework
 
Breaking Limits on Mobile HTML5 - TopConf Tallinn
Breaking Limits on Mobile HTML5 - TopConf TallinnBreaking Limits on Mobile HTML5 - TopConf Tallinn
Breaking Limits on Mobile HTML5 - TopConf Tallinn
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
 
From jQuery to App Store in 30 Minutes
From jQuery to App Store in 30 MinutesFrom jQuery to App Store in 30 Minutes
From jQuery to App Store in 30 Minutes
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
 
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone developmentiPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
 
WCLV13 JavaScript
WCLV13 JavaScriptWCLV13 JavaScript
WCLV13 JavaScript
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
L O S P I O O O J O S
L O S  P I O O O J O SL O S  P I O O O J O S
L O S P I O O O J O S
 
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in SugarSugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
 
Blogs como gerenciar
Blogs como gerenciarBlogs como gerenciar
Blogs como gerenciar
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
 
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
 

Semelhante a Images and PWA in magento

After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
yangdj
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
yangdj
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 

Semelhante a Images and PWA in magento (20)

Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
实战Ecos
实战Ecos实战Ecos
实战Ecos
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
Shared Element Transitions
Shared Element TransitionsShared Element Transitions
Shared Element Transitions
 
Building Robust jQuery Plugins
Building Robust jQuery PluginsBuilding Robust jQuery Plugins
Building Robust jQuery Plugins
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Dress Your WordPress with Child Themes
Dress Your WordPress with Child ThemesDress Your WordPress with Child Themes
Dress Your WordPress with Child Themes
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQuery
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
The Structure of Web Code: A Case For Polymer, November 1, 2014
The Structure of Web Code: A Case For Polymer, November 1, 2014The Structure of Web Code: A Case For Polymer, November 1, 2014
The Structure of Web Code: A Case For Polymer, November 1, 2014
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Drawing images
Drawing imagesDrawing images
Drawing images
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Images and PWA in magento

  • 1. Images & PWA in Magento © Rrap Software Pvt Ltd Pradip Shah, Founder, luroConnect
  • 3. © Rrap Software Pvt Ltd eCommerce trends Mobile Image quality Webp Magento direction No support for media queries No support for pixel ratio No support for webp Whine, Whine!
  • 4. © Rrap Software Pvt Ltd Problems of Magento Images • One solution is not suitable to all – code is not flexible • Ignores mobile completely • Mobile displays are better than desktop • Iphone X has 3x retina display • Most android phones are 2x • Major difference in image quality • Chrome & Firefox support webp – not Magento • Ignores custom transformations you may need
  • 5. © Rrap Software Pvt Ltd img srcset & picture Source : http://w3c.github.io
  • 6. © Rrap Software Pvt Ltd Magento 2 & image code module-catalog/Block/Product/AbstractProduct.php public function getImage($product, $imageId, $attributes = []){ return $this->imageBuilder->create($product, $imageId, $attributes); templates/product/list.phtml $productImage = $block->getImage($_product, $image); module-catalog/Block/Product/ImageBuilder.php public function create(Product $product = null, string $imageId = null, array $attributes = null){ $product = $product ?? $this->product; $imageId = $imageId ?? $this->imageId; $attributes = $attributes ?? $this->attributes; return $this->imageFactory->create($product, $imageId, $attributes); module-catalog/Block/Product/ImageFactory.php $data = [ 'data' => [ 'template' => 'Magento_Catalog::product/image_with_borders.phtml', 'image_url' => $imageAsset->getUrl(), 'width' => $imageMiscParams['image_width’], … 'product_id' => $product->getId() ], ]; return $this->objectManager->create(ImageBlock::class, $data);
  • 7. © Rrap Software Pvt Ltd Magento does not support devicepixelratio <theme>/templates/product/image_with_borders.phtml : <span class="product-image-container" style="width:<?= /* @escapeNotVerified */ $block->getWidth() ?>px;"> <span class="product-image-wrapper" style="padding-bottom: <?= /* @escapeNotVerified */ ($block->getRatio() * 100) ?>%;"> <img class="product-image-photo" <?= /* @escapeNotVerified */ $block->getCustomAttributes() ?> src="<?= /* @escapeNotVerified */ $block->getImageUrl() ?>" max-width="<?= /* @escapeNotVerified */ $block->getWidth() ?>" max-height="<?= /* @escapeNotVerified */ $block->getHeight() ?>" alt="<?= /* @escapeNotVerified */ $block->stripTags($block->getLabel(), null, true) ?>"/></span> </span> Guess what? You are hosed! The lowest element is generating a product-container
  • 8. © Rrap Software Pvt Ltd list.phtml … <div class="product-item-info" data-container="product-<?= /* @escapeNotVerified */ $viewMode ?>"> <?php $productImage = $block->getImage($_product, $imageDisplayArea); … <a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1"> <?= $productImage->toHtml() ?> </a>
  • 9. © Rrap Software Pvt Ltd <div class="product-item-info" data-container="product-<?= /* @escapeNotVerified */ $viewMode ?>"> <?php $productImage_dt = $block->getImage($_product, $imageDisplayArea); $productImage_dt_webp = $block->getImage($_product, $imageDisplayArea . “_webp”); $productImage_pd = $block->getImage($_product, $imageDisplayArea . “_pad”); $productImage_mo_2x = $block->getImage($_product, $imageDisplayArea . “_mo_2x”); $productImage_mo_webp_2x = $block->getImage($_product, $imageDisplayArea . “_mo_webp_2x”); … <a href="<?= $_product->getProductUrl() ?>" <span class="product-image-container"> <span class="product-image-wrapper“> <picture class="product-image-photo“> <source media="(max-width: 415px)" srcset="<?php echo $productImage_mo->toHTML(); ?>, <?php echo $productImage_mo_2x->toHTML();?> 2x" type="image/jpeg"> <img id="product-collection-image-<?php echo $_product->getId(); ?>" src="="<?php echo $productImage->toHTML(); ?> </picture> </span> </a> <theme>/templates/product/image_only.phtml : <?php $block->getImageUrl() ?>
  • 10. <div class="product-item-info" data-container="product-<?= /* @escapeNotVerified */ $viewMode ?>"> <?php $productImage_small = $product->getMediaConfig()->getMediaUrl($product->getData(‘small’); $productImage_large = $product->getMediaConfig()->getMediaUrl($product->getData(‘large’); … <a href="<?= $_product->getProductUrl() ?>" <span class="product-image-container"> <span class="product-image-wrapper“> <picture class="product-image-photo“> <source media="(max-width: 415px)" srcset="<?php echo $productImage_small.’?w=180&h=180&o=webp’?>, <?php echo $productImage_large.’?w=360&h=360&o=webp’?> 2x" type="image/webp"> <img id="product-collection-image-<?php echo $_product->getId(); ?>" src="="<?php echo $productImage->toHTML(); ?> </picture> </span> </a> What we do
  • 11. © Rrap Software Pvt Ltd Synchronous image generation • Traditionally Magento generated images when the frontend would load – category page with 32 items • Many CDN based image generation is synchronous • i.e. while the image is being fetched it is being converted • However, due to HTTP/2, the requests will go out in parallel Browser php img1 img2 img3 Request Response
  • 12. © Rrap Software Pvt Ltd Magento 2.3 and image code Asynchronous generation of images module-catalog/Observer/ImageResizeAfterProductSave.php if (!(bool) $product->getId()) { foreach ($product->getMediaGalleryImages() as $image) { $this->imageResize->resizeFromImageName($image->getFile()); } } else { module-media-storage/Service/ImageResize.php public function resizeFromImageName(string $originalImageName) { … foreach ($this->getViewImages($this->getThemesInUse()) as $viewImage) { $this->resize($viewImage, $originalImagePath, $originalImageName); private function resize(array $viewImage, string $originalImagePath, string $originalImageName) { $imageParams = $this->paramsBuilder->build($viewImage); $image = $this->makeImage($originalImagePath, $imageParams); … $image->resize($imageParams['image_width'], $imageParams['image_height’]); … $image->save($imageAsset->getPath()); Guess what? each image will have many variations use them or not! Fix the view.xml in your themes now.
  • 13. © Rrap Software Pvt Ltd PWA and images • Fetching a correctly sized image You should get a higher resolution image if you are on a high pixel density device. A good rule of thumb is to multiply the size of the image you display by the pixel ratio. var image = getImage({ width: PixelRatio.getPixelSizeForLayoutSize(200), height: PixelRatio.getPixelSizeForLayoutSize(100), }); <Image source={image} style={{width: 200, height: 100}} /> https://facebook.github.io/react-native/docs/0.8/pixelratio
  • 14. © Rrap Software Pvt Ltd PWA has choices of
  • 15. © Rrap Software Pvt Ltd
  • 16. © Rrap Software Pvt Ltd https://headless.page/
  • 17. © Rrap Software Pvt Ltd PWA has potential but don’t use Magento for images
  • 18. © Rrap Software Pvt Ltd www.hartsofstur.com https://www.hartsofstur.com/api /catalog/products/57
  • 19. © Rrap Software Pvt Ltd Same image to all devices
  • 20. © Rrap Software Pvt Ltd Other image services • Imagekit • Great Indian Bootstrapped SaaS story • Piggyback on a paid cloudflare account • Cloudflare does webp conversion • Imagekit backend offers image optimization • Issue : Not application aware, conversion is synchronous, cf is distributed • Question : Do they store or just convert (cf is distributed remember) • Fastly • Magento cloud partner – application aware • CDN with Varnish on edge – distributed varnish • Image optimization is synchronous
  • 21. © Rrap Software Pvt Ltd Resources • https://medium.com/@bjoern.meyer/pwa-ecommerce-solutions- compared-83bb498433e9 • https://headless.page/
  • 22. © Rrap Software Pvt Ltd https://www.luroConnect.com/ Where to find us https://www.luroConnect.com/ info@luroConnect.com @luroconnect