Does anyone have a way to load a third
# package-development
t
Does anyone have a way to load a third party javascript earlier in the chain? As in, https://cdn.example.com/myjs.js ? When I reference it using assetsService.load from my own js-file to load the third party file, which works, but I would like it to load eariler 🙂 Anyone know some magic I've missed? 🙂 (Adding it to Scripts in my PackageManifest results in an error).
j
Create your own script,
load.js
, reference that in the PackageManifest. Then in that script:
Copy code
javascript
const script = document.createElement('script');
script.src = 'https://cdn.example.com/myjs.js';
document.body.appendChild(script)
Create your own
load.js
and reference that in your PackageManifest, then:
Copy code
javascript
const script = document.createElement('script');
script.src = 'https://cdn.example.com/myjs.js';
document.body.appendChild(script)
t
ooo, that's smart 🙂 That should actually work. Thanks!
j
I've had to use this trick a few times - Umbraco doesn't support loading JS Modules into the backoffice, so this is the only way (with
script.type = "module";
)
t
Worked wonders! Thank you again 🙂
j
You're welcome, glad it did what you needed!
5 Views