I have checked my settings for caching, they are “standard” and under Media → Imageloading is ‘lazy’ (but we fix it already in twig).
Are there any other options/settings or tags who i can try?
You still might see no effect depending on the size of the page and the position of the images.
Lazy loading is a browser feature. Once the attribute loading="lazy" has been set on the <img>, it is out of the hands of Grav and up to the browser to decide how to deal with lazy loading. Each browser has its own decision tree to decide when to load images. And that might not be what you would expect, or want…
It has nothing to do with cropResize or lightbox. Also changing Grav’s options does not effect how the browser decides to deal with lazy loading.
You said:
but there is no effect
What effect did you expect?
How did you check for the effect?
Page length/image position
How long is your page. Or, how much scrolling is needed to reach the images.
What happens if you make the text above the images 2, 3 or 10 times longer?
@pilot23, So far, not much information is provided accept for “without effect” or “without lazyload effect”.
When I add 300 images of 1200x800px to the bottom of page Typography (fresh Grav 1.7.30 installation), none of the images is loaded until scrolling down the page near the end. Hence, lazy loading is working, albeit not yet as efficient as one would like.
As said, the browser decides when and how many images to load depending on, for example, the image size, vertical position of images relative to page length, viewport dimensions, scrolling speed, etc.
Using above simple test, about 200+ images are being lazy loaded at once when scrolling down near the end of the page. Why so many? Before loading the images, the browser has no idea about the size of the images.
Do you apply height/width styling rules to the images in css?
Adding image dimensions in css (or adding height/width directly to the <img> tag) will give the browser more information to calculate/predict how many images should be loaded on scrolling.
Adding dimensions will also prevent Cumulative Layout Shift.
When adding the following css to above test, Chrome only loads 1-2 images at a time when scrolling down:
img {
width: 1200px;
}
Notes:
You should probably add a class to the images using
and use ‘.my-class’ as selector for the css instead of ‘img’.
You can have Grav add dimensions automatically to each image by setting the following in file /user/config/system.yaml:
images:
cls: # stands for Cumulative Layout Shift
auto_sizes: true
But often, you will need to create different image sizes (srcsets) depending on the size of the device and add different dimensions to css depending on the viewport of the device.
Also be aware that the gallery being used might interfere with lazy loading.