Async Load JavaScript Files with Callback

前端 未结 6 1257
礼貌的吻别
礼貌的吻别 2020-12-05 08:26

I am trying to write an ultra simple solution to load a bunch of JS files asynchronously. I have the following script below so far. However the callback is sometimes called

6条回答
  •  -上瘾入骨i
    2020-12-05 09:05

    There is nothing wrong with your code from what I can tell, this is just a bug in Chrome (it does it with window.onload also.)

    I'd add it to the function that is triggered in the "load" function. If the variable exists, execute the JS code, but if it doesn't, use a setTimeout to check again in 500ms or so.

提交回复
热议问题