Lightning Web Component specially designed to easily optimize image loading
lightning-image
is a Lightning Web Component specially designed to easily
optimize image loading. It’s optimized for fixed width/height images and images that stretch the full-width of a container.
Using Salesforce CRM Content thumbnail rendition servlet to optimize the thumbnail’s size.
Large, unoptimized images dramatically slow down your site.
But creating optimized images for websites has long been a thorny problem.
Ideally you would:
Doing this consistently across a site feels like sisyphean labor. You manually
optimize your images and then… several images are swapped in at the last minute
or a design-tweak shaves 100px of width off your images.
This isn’t ideal. Optimized images should be easy and the default.
lightning-image
works seamlessly with Salesforce CRM Content thumbnail rendition servlet. To produce perfect images,
you need only:
lightning-image
and use it in place of the built-in img
lightning-image
.There are two ways to install this component:
sfdx force:auth:web:login
git clone https://github.com/hanabiiii/lightning-image.git
cd lightning-image
sfdx force:source:deploy -m LightningComponentBundle:lightningImage -u [your-account]
Click this link to install the unmanaged package in your org.
Please check the example component: Case Attachments.
lightning-image
supports showing different images at different breakpoints, which is known as Resolution switching: Different sizes.
lightning-image
propsName | Type | Description |
---|---|---|
title |
string |
Passed to the img element. |
alt |
string |
Passed to the img element. Defaults to an empty string. alt="" |
loading |
string |
Set the browser’s native lazy loading attribute. One of lazy or eager . Defaults to lazy . |
src |
string / array |
Set the image src. Array object to support resolution switching { source, sourceSize , conditionSize , conditionSetSize }. |
wrapperClass |
string |
Spread into the default class of the wrapper element. |
wrapperStyle |
string |
Spread into the default styles of the wrapper element. |
imageClass |
string |
Spread into the default class of the actual img element. |
imageStyle |
string |
Spread into the default styles of the actual img element. |
placeholderColor |
string |
Set a colored background placeholder. You can also pass in any valid color string. Defaults to lightgray . |
imagePlaceholder |
named slot |
Used to replace the default placeholder. |
durationFadeIn |
number |
Fading duration is set up to 500ms by default. |
onload |
event |
An event that is called when the full-size image has loaded. |
onstartload |
event |
An event that is called when the full-size image starts loading. |
onerror |
event |
An event that is called when the image fails to load. |