Good Otávio after thinking of mirabolosas solutions with Ajax both with back-end and with front, I began to think "this problem is not current will not already solved ?" and the answer was yes, there is a library called Owl Carousel 2 and one of its many features is Lazy Loading or lazy loading, see the following code snippet (which is in the documentation itself):
HTML
<div class="owl-carousel owl-theme">
<img class="owl-lazy" data-src="https://placehold.it/350x450&text=1" data-src-retina="https://placehold.it/350x250&text=1-retina" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x650&text=2" data-src-retina="https://placehold.it/350x250&text=2-retina" alt="">
<picture>
<source class="owl-lazy" media="(min-width: 650px)" data-srcset="https://placehold.it/350x250&text=3-large">
<source class="owl-lazy" media="(min-width: 350px)" data-srcset="https://placehold.it/350x250&text=3-medium">
<img class="owl-lazy" data-src="https://placehold.it/350x250&text=3-fallback" alt="">
</picture>
<img class="owl-lazy" data-src="https://placehold.it/350x250&text=4" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x250&text=5" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x250&text=6" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x250&text=7" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x250&text=8" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x400&text=9" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x400&text=10" alt="">
<img class="owl-lazy" data-src="https://placehold.it/350x450&text=11" alt="">
</div>
Javascript (jQuery and Owl Carousel 2)
$(document).ready(function(){
$('.owl-carousel').owlCarousel({
items:4,
lazyLoad:true,
loop:true,
margin:10
});
})
And ready with this simple code the magic is ready, it works like this, you create your div with the hundreds of images you need, but only the number of images set in items
in javascript will be loaded along with the page, the other images will only actually be downloaded when the user requests them through some event defined by you, tested here inspecting the traffic of the network and the library really fulfills what promises, found this solution much simpler and cleaner than I had thought and highly recommend.
If you want to see the full example is available at https://owlcarousel2.github.io/OwlCarousel2/demos/lazyLoad.html and all documentation of the use of the library seemed to me clear and clean.
I can think of a solution involving Ajax to do a cool optimization, but it gets a little complicated having to basically do a complete project to get you this solution, Couldn’t you publish your project somewhere so I can test solutions or create a smaller version of the project and make it available to us ? That way I can focus on solving your problem instead of focusing on doing all the implementation until I start thinking about it
– viniciusxyz
@Viniciusvieira So, but in this case, it’s just that same code, imagine it has a folder with 111 images that are named equal but with a different number at the end... all I did was put a for that loads the images incrementing the number, I didn’t want to add all 111 images in hand inside the code
– Otavio Souza Rocha
@Viniciusvieira there is no backend behind this gallery yet
– Otavio Souza Rocha
That’s right, as soon as I get home I’ll try to put into practice the solution I have in mind
– viniciusxyz