Enable lazy loading globally
You can enable lazy loading for all widgets in three ways. Choose the method that fits your setup.Method 1: Script tag attribute
Adddata-tallysight-widget-loading="lazy" to the SDK <script> tag. This is applied before the SDK initializes and requires no JavaScript.
Method 2: enableLazyLoading()
Call Tallysight.enableLazyLoading() after the SDK is ready. This is convenient when you want to conditionally enable lazy loading based on page context or user preferences.
Method 3: Tallysight.configure()
Pass lazyLoad options through configure(). You can chain this with other configuration calls.
disableLazyLoading():
Per-widget loading strategy
Individual widget elements can override the global lazy loading setting using thedata-tallysight-widget-loading attribute. This lets you mix strategies on the same page — for example, loading a hero widget eagerly while deferring widgets further down the page.
| Value | Behavior |
|---|---|
eager | Always loads immediately, ignoring the global lazy loading setting |
lazy | Always uses lazy loading, ignoring the global setting |
auto | Follows the global lazy loading configuration (default) |
Preloading a bundle
Tallysight.preloadWidget(type) fetches and caches a widget bundle without rendering anything. Use it when you want to warm up a bundle in the background so the widget is ready to display instantly when needed.
How the IntersectionObserver works
The SDK calculates arootMargin based on the widget element’s actual height — or defaults to 200 px when the element has no rendered height yet. This means the bundle starts loading before the widget fully enters the viewport, so it appears to load instantly as the visitor scrolls.
The SDK also cleans up observers for elements that are removed from the DOM, preventing memory leaks on pages that add and remove widgets dynamically.
IntersectionObserver is supported in all modern browsers. The SDK does not include a polyfill. If you need to support older environments, either avoid lazy loading or supply your own IntersectionObserver polyfill.