An alternate approach to solving this kind of problem:
Use the built-in setInterval (a way to repeatedly call a JavaScript function every X seconds) to attempt to retrieve the dash component class/id you are after, and then turn off the calls with a function called clearInterval:
function myFunction() {
let someComponentClass = document.getElementsByClassName("...");
if(someComponentClass.length > 0) {
clearInterval(refreshID);
}
}
// call this function every 250 ms
let refreshID = setInterval(myFunction, 250);
Hmm, I imagine that all you have to do is add a check in the if line that determines whether the object is defined or not.
That would look something like this:
function myFunction() {
let someComponentClass = document.getElementsByClassName("...");
if(someComponentClass && someComponentClass.length > 0) {
clearInterval(refreshID);
}
}
// call this function every 250 ms
let refreshID = setInterval(myFunction, 250);
The problem is exactly like what this post suggests, and I’ve tried the solution from @akulidjian and it worked, but it’s not the optimal solution. And I don’t want to download third-party libraries as other posts suggest which is not maintained. I am just wondering if there’s any official way to append the scripts after the components are loaded, instead of scripts being loaded in the beginning. And client_side callback does not work in this case as it is an animation js that needs to run infinitely.