Enabling Viewport Loading for Your Custom Widget

You can enable viewport loading for your custom widget so that it's loaded only when being in the visible area of the screen.

Context

When viewport loading is selected as the loading optimization setting for the story, only contents in the visible area of the screen are loaded in view time.

Viewport loading is supported for custom widgets. However, as a custom widget developer, you need to enable viewport loading for your custom widget.

Procedure

  1. Set supportsViewportLoading to true in the custom widget JSON file.
  2. Optional: In Web Component JavaScript, fire the customWidgetRenderComplete event after the custom widget has finished rendering.
    The step is highly recommended for cases such as export if the custom widget supports export, because the export framework needs to know when the widget has finished rendering in order to export its contents correctly. Note that the export framework waits for up to a minute for the customWidgetRenderComplete event before timeout.

Results

When viewport loading is enabled for your custom widget, you can open Performance Insights and refer to the following processes to check whether the custom widget's been loaded:
  • Load resource file of custom widget <widget name>: The process involves downloading the custom widget's resource file. It appears in the loading sequence, whether the custom widget supports viewport loading or not.

  • Render custom widget <widget name>: The displayed loading time includes the time required by the custom widget framework to initialize the custom widget and retrieve data for it. However, it doesn’t include the time taken by the widget to render itself with the data as it can be hard to measure, particularly if animations are involved during rendering.