You've polished the tooltip's behavior with animations. Now it's time to ensure great performance.

Since a tooltip displays only when a user interacts with the target, the tooltip does not need to be created until interaction. If a page uses a lot of tooltips, which is not uncommon, adding this optimization can speed up initial page rendering by a meaningful amount.

To do this, you'll create a function users will call with a tooltip target element and a callback that will render tooltip content on demand when its needed.

Add a static method to the SimpleTooltip class called lazy. It will setup event listeners on the target element that listen on the same events used to trigger the tooltip. The listener creates the tooltip element and calls the user callback with it to fill in the content before showing it. Near the top of the class definition, add:

simple-tooltip.

Permalink to "simple-tooltip."

Now open the my-content. module and change the greeting tooltip to use the lazy method. To do so, first remove the inline tooltip:

my-content.

Permalink to "my-content."

Then define a firstUpdated lifecycle callback to setup the call to lazy.

The tooltip for the greeting element should work the same now, but it's created on demand when one of the "enter" events is triggered. If you do this for all tooltips, you can ensure they don't impose a performance penalty on initial page render.