[Help]: Optimizing Performance with Lazy Rendering #835
-
SummaryI've run into a bit of a snag with my implementation. I'm dealing with a carousel that has hundreds of slides, each one a custom component. As you can imagine, rendering all of these at once is causing some serious performance issues, almost to the point of crashing the page. I've been trying to implement a solution where only the slides currently in view are rendered dynamically. However, I'm not having much luck getting it to work. I was hoping you might be able to give me some guidance or point me in the right direction? Here's what I've got so far: https://stackblitz.com/edit/github-yqleaf?file=app.vue Any help would be greatly appreciated. Thanks in advance! If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationNo response CodeSandbox exampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@meirroth you can keep track of which slides you want to render using both the let slidesInView = emblaApi.slidesInView(); // initial state
emblaApi.on('slidesInView', (emblaApi) => {
slidesInView = emblaApi.slidesInView();
}); And then, add a watcher that will update as soon as Note
Best, |
Beta Was this translation helpful? Give feedback.
-
@davidjerleke I tried following your direction, it works better, but still doesn't scroll smoothly, any ideas? |
Beta Was this translation helpful? Give feedback.
@meirroth does this StackBlitz lag for you? It doesn't for me. I've made some modifications there. The most significant is that I only attach a single
slidesInView
listener and not add a new listener every time the state changes. See comments in code.Best,
David