Lazy Loading Images and Video in Owl Carousel

Carousels often contain many large images, yet only a few are visible at any moment. Loading all of them at once wastes bandwidth and delays the rest of the page. Owl Carousel's lazy loading feature defers each image until its slide is about to appear.
Why Image Weight Matters
Images usually account for the largest share of a web page's download size, and carousels concentrate many of them in one place. Every unnecessary image delays the moment the page becomes usable, consumes mobile data and drains battery. Search engines also measure loading performance through Core Web Vitals, so a heavy carousel near the top of a page can affect how the whole page is assessed.
Lazy loading addresses the problem at its source by downloading only what the visitor is about to see. On a carousel with twelve slides and three visible at a time, the saving on first load can approach three-quarters of the slider's image weight. The visitor notices nothing except a page that appears sooner.
Enabling Lazy Loading
Set lazyLoad: true, then give each image the class owl-lazy and move its source into a data-src attribute. The library copies the value into src when the slide approaches the visible area.
<div class="owl-carousel owl-theme">
<img class="owl-lazy" data-src="img/coast.jpg" alt="Rocky coastline" width="800" height="533">
<img class="owl-lazy" data-src="img/forest.jpg" alt="Pine forest" width="800" height="533">
</div>
$(".owl-carousel").owlCarousel({
items: 2,
lazyLoad: true
});
For high-density screens, add a data-src-retina attribute pointing to a larger file. The library selects it automatically on displays with a device pixel ratio above one.
Preloading Neighbouring Slides
Waiting until a slide is visible can produce a brief blank frame as the image downloads. The lazyLoadEager option preloads a set number of items beyond the visible range, so images are usually ready by the time the user reaches them. A value of one or two strikes a good balance between speed and savings.
Background Images
The owl-lazy class also works on elements other than images. When applied to a div with a data-src attribute, the library sets the value as a CSS background image, which suits full-bleed hero slides.
Preventing Layout Shift
An image without dimensions occupies no space until it loads, causing the content below to jump. Always supply width and height attributes, or reserve space with the CSS aspect-ratio property. This keeps the carousel stable and protects your Cumulative Layout Shift score.
.owl-carousel .owl-lazy {
aspect-ratio: 3 / 2;
width: 100%;
object-fit: cover;
background: #eef2ee;
}
Embedding Video
The video module displays YouTube and Vimeo clips as thumbnails with a play icon, loading the actual player only when the user chooses to watch. Enable it with video: true and wrap each link in an element with the class item-video:
<div class="item-video">
<a class="owl-video" href="https://www.youtube.com/watch?v=VIDEO_ID"></a>
</div>
$(".owl-carousel").owlCarousel({
items: 1,
video: true,
videoHeight: 360,
lazyLoad: true
});
When the carousel moves to another slide, the library stops the playing video, so sound does not continue from an off-screen clip.
Native Lazy Loading
Modern browsers support loading="lazy" on images. It is effective for images outside the carousel, but inside a slider the browser cannot always predict which slides are about to appear. The library's own mechanism, which knows the carousel's position, is the more reliable choice there. Avoid applying both techniques to the same image.
Do Not Lazy-Load the First Slide
Lazy loading should apply to images the visitor may not see immediately. When a carousel sits at the top of the page, its first visible image is often the Largest Contentful Paint element, the metric search engines use to judge loading speed. Deferring that image delays the metric. Give the slides that are visible on load a normal src attribute and reserve owl-lazy for the rest.
<div class="owl-carousel">
<img src="img/hero-1.jpg" alt="Coastal path" width="1600" height="700" fetchpriority="high">
<img class="owl-lazy" data-src="img/hero-2.jpg" alt="Harbour" width="1600" height="700">
<img class="owl-lazy" data-src="img/hero-3.jpg" alt="Cliffs" width="1600" height="700">
</div>
Styling the Loading State
The core stylesheet fades lazy images in once they load, starting them at zero opacity. A placeholder background on the slide therefore shows through until the image arrives. A gentle animated shimmer communicates that content is on its way:
.owl-carousel .item {
background: linear-gradient(90deg, #eef2ee 25%, #f7f9f7 50%, #eef2ee 75%);
background-size: 200% 100%;
animation: shimmer 1.4s linear infinite;
}
.owl-carousel .item.is-loaded { animation: none; background: none; }
@keyframes shimmer { to { background-position: -200% 0; } }
Listening for Load Events
The library emits load.owl.lazy before an image starts loading and loaded.owl.lazy once it has finished. The second event is the right moment to remove placeholder styling or reveal captions that depend on the image:
$(".owl-carousel").on("loaded.owl.lazy", function (e) {
$(e.element).closest(".item").addClass("is-loaded");
}).owlCarousel({ items: 3, lazyLoad: true, lazyLoadEager: 1 });
Choosing File Formats and Sizes
Lazy loading reduces how many images download, but each image should still be as light as possible. WebP files are typically much smaller than equivalent JPEGs and are supported by all current browsers. Export images at the largest size they will actually be displayed, multiplied by two for high-density screens if you use data-src-retina, and no larger.
Measuring the Benefit
Open the network panel in your browser's developer tools, filter by images and reload the page. Without lazy loading, every slide image appears in the list straight away; with it, only the visible slides and any eagerly preloaded neighbours should load. Lighthouse reports in Chrome summarise the effect on total page weight and on loading metrics, making it easy to compare configurations.
Key Takeaways
- Mark deferred images with
owl-lazyand adata-srcattribute. - Load the first visible slide normally to protect Largest Contentful Paint.
- Reserve space for every image to prevent layout shift.
- Use
lazyLoadEagerto preload one or two neighbouring slides.
Summary
Enable lazyLoad, preload one or two adjacent items, reserve space for every image and use the video module for embedded clips. Together these measures keep carousels light without compromising the viewing experience.


