Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Sheiles 67 posts 337 karma points
    Nov 04, 2022 @ 06:07
    David Sheiles
    0

    Detecting if the new UUI JS library is included

    Hi,

    I'm building a package that uses the new Umbraco.UI library. The package covers Umbraco 8, 9 and 10, so not all versions will include the UUI Javascript.

    Rather than load the script twice on newer V10 installs that include the library by default, what's the best way to detect in javascript if its already loaded?

    Wondering if anyone has a "best practice" for this as yet?

  • David Sheiles 67 posts 337 karma points
    Nov 04, 2022 @ 07:41
    David Sheiles
    0

    Here's my solution thus far. I have a separate JavaScript file that the package manifest references with the following code:

    if (typeof uui === 'undefined') { var script = document.createElement('script'); script.src = "https://cdn.jsdelivr.net/npm/@umbraco-ui/uui@latest/dist/uui.min.js"; document.head.appendChild(script); }

    This runs on load and if the uui object doesn't exist, it loads the latest from the CDN.

    It seems to work well, but it does have the possibility of another package doing the same check and loading the script multiple times.

Please Sign in or register to post replies

Write your reply to:

Draft