Hello,
I'm trying to load the P5 library with two addon libraries, P5Dom and P5Sound, on a react application.
On the traditional stack just adding them to the header in order works fine.
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js">
I've tried external source and bringing the scripts internal and run into the addons loading before P5 loads. Making both addons dependent on the P5 script doesn't fix the issue
Network stack loads them in correct order, but the addons are much smaller and finish/execute before their dependent script is loaded
I've also tried lazy loading the libraries with a call back to load the addons, but then they don't get initialized on the page just added to the header.
Looking for help on what I'm missing to get these loaded in order.
Is there a way to force scripts to wait for the dependent script to finish loading?
Regards,
Don
EDIT:
Here's how you can make scripts dependent on one another in Mobile and Reactive Web:
https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Mobile_Interfaces/Adding_Data_and_Logic/Script
Thank you for the reply Andrew.
In my post above I have a screenshot of that dependency where P5_sound is dependent on P5_min.
React will still load them asynchronously. P5Sound's request is sent after P5_min but downloads and executes due to it being significantly smaller payload.
This is jank, but wrapping the dependent scripts in a timeout function to delay their load solves the issue. I would much prefer a call back feature to load dependent libraries after the main library has loaded.
Donald Monpas wrote:
Apologies for missing that...
It's possible that you might need to consider turning your P5 stuff into one or more React components to make this work. I think part of the issue is that you're wanting to use a JS library that draws on the screen with another library that is abstracting and controlling the rendering lifecycle, and then also dealing with dependent libraries to boot.
Any chance you can share a small OML of the working version with the timeout function? With that as a starting point, I can try some ideas to see if there's an easier (and less janky) way.
Hi Donald,
I think you should add depedency of RequireScript client action from system and use that. It works exactly like you want.
Here is its document link.
https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/System_Actions#RequireScript
Can you look at my post about this at the end of https://www.outsystems.com/forums/discussion/65156/javascript-error/#Post270145
Try to add the data-os-finished="true" attribute to your <script> tags and let me know if that solves the problem.
Thank you,
Anthony