atomiks / tippyjs

Tooltip, popover, dropdown, and menu library
https://atomiks.github.io/tippyjs/
MIT License
11.92k stars 520 forks source link

[Question] Load tippy (and popper) async #898

Closed yellow1912 closed 3 years ago

yellow1912 commented 3 years ago

I wonder if it's possible to do something like this:

<script src="https://unpkg.com/@popperjs/core@2" async></script>
<script src="https://unpkg.com/tippy.js@6" async></script>

The problem is that there is no guaranty that popperjs will be loaded first, so I was thinking if it's possible to do something like this:

<script src="https://unpkg.com/@popperjs/core@2" async onload="triggerEventTellingPopperIsLoaded"></script>
<script src="https://unpkg.com/tippy.js@6" async onload="triggerEventTellingTippyIsLoaded"></script>

Only once both are loaded then tippy is initialized. Is it possible like that? I'm thinking it's possible to do something like this:

Instead of loading https://unpkg.com/tippy.js@6 directly, I could build my own file with something like this

tippy.js

if (popperIsLoaded) {
import tippy from 'tippy.js';
}

I feel like something is wrong with this though?

atomiks commented 3 years ago

Use defer not async