Code section executed upon every refresh VS at load

Hi, several panels have 2 section: once is executed just at load, and the other one at every refresh.
In this particular case I’m using the HTML node and I need to run a piece of javascript only at the download; the refresh is off. The code call an external source which have some callback functions. If I just load the page nothing happens, (this is my problem), but it’s enough any action, for example simply open the inspection tool, that then everything works perfectly. The same happens even if I’m in edit mode: I simply stretch a little bit the edit section, or toggle on/off the table mode and from now on everything works great.
I cannot understand this behavior and i don’t know how to overcome it.