Lazy loading uses the browser’s IntersectionObserver API to defer loading widget bundles until a widget is about to enter the viewport — reducing initial page load time. Instead of fetching every bundle when the page first loads, the SDK waits until each widget is within range of the screen before fetching its bundle. This is especially useful for pages with several widgets placed below the fold, where many bundles would otherwise be downloaded before the visitor ever scrolls to them.Documentation Index
Fetch the complete documentation index at: https://docs.tally.site/llms.txt
Use this file to discover all available pages before exploring further.
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 user 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.