Lazy Load
A performance optimization pattern that loads images only for visible panels by combining the renderOnlyVisible option with the visibleChange event.
- JavaScript
- React
- Vue@3
Summary
Key Options/Events
| Item | Type | Default | Description |
|---|---|---|---|
renderOnlyVisible | boolean | false | Render only visible panels |
visibleChange | VisibleChangeEvent | - | Fired when the visible panels change |
Event Properties
| Property | Type | Description |
|---|---|---|
added | Panel[] | Panels that newly entered the viewport |
removed | Panel[] | Panels that left the viewport |
visiblePanels | Panel[] | All currently visible panels |
Behavior Comparison
| Method | Image Load Timing | Best For |
|---|---|---|
| Normal loading | All panels loaded at once | Few panels (10 or less) |
| Lazy loading | Loaded when entering the viewport | Many panels (tens to hundreds) |
Details
How It Works
renderOnlyVisible: truerenders only visible panels- Detect newly visible panels from the
addedarray in thevisibleChangeevent - Load images for those panels and record the load status
- Images that have already been loaded are not loaded again (tracked with a Set)
Initial Load
Since visibleChange has not fired yet right after Flicking initialization, you need to load images for the initially visible panels in the ready event.
Related Options
- Relationship with
renderOnlyVisible: This option is the core. It reduces DOM overhead by skipping rendering of non-visible panels - Relationship with
bound: Usingbound: truetogether provides smooth scrolling without empty space at the end - Relationship with
align:align: "prev"is suitable for list-type layouts
Use Cases
When should you use this?
- Galleries with many images (50+)
- Image optimization in infinite scroll feeds
- Reducing network load in mobile environments
Notes
Caution
renderOnlyVisibleis recommended for use in framework (React, Vue) environments- Panels in the
addedarray of thevisibleChangeevent arePanelobjects and can be identified by theirindexproperty - During initial load, you need to separately handle visible panels in the
readyevent
Related Links
Related Options
renderOnlyVisible: Render only visible panelsbound: Boundary restriction
Related Demos
- Render Only Visible: On/off comparison of the renderOnlyVisible option
- Virtual Scroll: Handling large numbers of panels with virtual mode