Optimize Size Update
Use the optimizeSizeUpdate option to skip forced panel rendering (forceRenderAllPanels) when the size change occurs on an axis irrelevant to the Flicking direction, optimizing performance.
Try swiping through panels and compare the flickering difference between the two carousels.
With optimizeSizeUpdate: false, all 200 panels are inserted into and removed from the DOM on every height change, causing flickering.
With true, this process is skipped when only the height changes, resulting in smooth operation without flickering.
- JavaScript
- React
- Vue@3
Summary
Key Options
| Option | Type | Default | Description |
|---|---|---|---|
optimizeSizeUpdate | boolean | false | Skip forced panel rendering when irrelevant axis changes based on direction |
Direction-Based Behavior
| Flicking Direction | Force Rendering Condition with optimizeSizeUpdate: true |
|---|---|
horizontal (default) | Force renders all panels only when width changes |
vertical | Force renders all panels only when height changes |
Details
Flow: When autoResize Detects a Height Change
In an autoResize: true + renderOnlyVisible: true environment, the following flow occurs when only the viewport height changes:
1. Viewport height changes (panel height differences, external layout changes, etc.)
2. autoResize's ResizeObserver detects the height change
-> flicking.resize() called
3. Inside resize(), forceRenderAllPanels()
-> All hidden panels are inserted into DOM (cameraEl.appendChild)
-> Browser briefly renders all panels -> unnecessary DOM manipulation!
4. renderer.render()
-> Non-visible panels removed from DOM again
With optimizeSizeUpdate: true applied:
-> If width hasn't changed in a horizontal Flicking
-> forceRenderAllPanels() is skipped -> DOM manipulation prevented
How optimizeSizeUpdate Works
Inside Flicking's resize(), forceRenderAllPanels() is called to accurately measure all panel sizes. This method renders all panels to the DOM so their sizes can be measured.
When using renderOnlyVisible or virtual rendering, non-visible panels are normally removed from the DOM. During resize(), inserting and removing all these panels becomes increasingly expensive as the panel count grows.
With optimizeSizeUpdate: true, this forced rendering is skipped when only the axis irrelevant to the Flicking direction has changed.
resize() internal flow:
1. viewport.resize() <- Always executed
2. forceRenderAllPanels() <- Part controlled by optimizeSizeUpdate
- false: Always renders all panels to DOM
- true: Only renders when the relevant axis changes (horizontal->width, vertical->height)
3. updatePanelSize() -> render() <- Always executed
Prerequisites
This option is effective when used with autoResize: true in combination with renderOnlyVisible: true or virtual rendering.
In normal rendering mode, all panels are always in the DOM, so forceRenderAllPanels() has virtually no cost.
Use Cases
autoResize: true+renderOnlyVisible: true+ many panels: Reduces unnecessary DOM manipulation when only viewport height changes, improving performance- Horizontal slider inside vertical scroll: Prevents unnecessary rendering of hidden panels on height changes from scrolling
- Virtual rendering environment: Prevents unnecessary render/unmount of virtual panels
Notes
- Only works when
autoResize: true - Has no effect without
renderOnlyVisibleor virtual rendering - If panel size depends on the container height (e.g.,
height: 100%), using this option may prevent panel sizes from being updated
Related Links
Related Options
optimizeSizeUpdate: Size update optimizationautoResize: Auto resize (dependent option)renderOnlyVisible: Render only visible panels
Related Demos
- Auto Resize: Resize detection method settings
- Resize Debounce: Control resize call frequency
- Render Only Visible: Render only visible panels