Description
The other question about the adaptation is whether it would not make sense to integrate a Lazyload libary? 99% of the lazyload libary triggers the images with the img class name lazyload and data-src. I would also suggest lazysizes here in combination with Pagebuilder. We have had the best experience with this, also because it is not dependent on jquery.
It also works automatically in conjunction with any kind of JS-/CSS-/Frontend-Framework (jQuery mobile, Bootstrap, Backbone, Angular, React, Ember (see also the attrchange/re-initialization extension)), Vue is also avaiable: https://www.npmjs.com/package/vue-lazysizes
https://npmcharts.com/compare/lazysizes,jquery-lazy,lozad?interval=360
https://github.com/magento-devdocs/pagebuilder-examples/tree/master/Image/LazyLoading
https://github.com/aFarkas/lazysizes
Of course, there is the loading lazy function, but it does not yet work well in all areas like sliders, ajax, ko, so you would have to integrate it better natively: https://web.dev/browser-level-image-lazy-loading/#how-do-i-handle-browsers-that-don't-yet-support-lazy-loading
<script>
if ('loading' in HTMLImageElement.prototype) {
const images = document.querySelectorAll('img[loading="lazy"].lazyload');
images.forEach(img => {
if(img.dataset.src !== ''){
img.src = img.dataset.src;
img.classList.add("lazyloaded");
img.classList.remove("lazyload");
}
});
}
window.lazySizesConfig = window.lazySizesConfig || {};
window.lazySizesConfig.init = false;
lazySizesConfig.loadHidden = false;
lazySizesConfig.expand = 0;
lazySizesConfig.loadMode = 1;
</script>
var config = {
paths: {
'lazysizes': 'lib/lazysizes/lazysizes.min',
'lazysizesAttrchange': 'lib/lazysizes/plugins/attrchange/ls.attrchange.min',
},
deps: [
'lazysizesAttrchange'
],
shim: {
'lazysizes': {
exports: 'lazySizes'
},
'lazysizesAttrchange': {
deps: ['lazysizes']
}
}
};
Perhaps a little more insight, lazysizes can be used not only for images but also for div containers. and that brings another advantage. Predictable isolation of a DOM subtree: https://web.dev/content-visibility/
like:
<div class="block block-minicart ui-dialog-content ui-widget-content lazyload" data-role="dropdownDialog" id="ui-id-1">
<style>
.lazyloaded,
.content-visibility-auto.[aria-hidden="false"],
.content-visibility-auto:not(.lazyloaded) {
content-visibility: visible;
}
.lazyload {
content-visibility: auto;
}
.content-visibility-auto.[aria-hidden="true"],
.content-visibility-auto.lazyload {
content-visibility: hidden;
}
</style>
Metadata
Metadata
Assignees
Type
Projects
Status