How to wait for another JS to load to proceed operation?

前端 未结 4 1243
醉酒成梦
醉酒成梦 2020-12-08 10:31

I have an issue. One of my JS scripts needs Facebook SDK and Twitter widgets JS to load first. Facebook creates FB object, Twitter creates twttr ob

4条回答
  •  佛祖请我去吃肉
    2020-12-08 10:44

    If the Facebook scripts are being loaded asynchronously, Facebook has a supported way to execute code when it's library loads which should be much more efficient than polling for it. See this answer for an example: https://stackoverflow.com/a/5336483/816620.

    If the Facebook scripts are being loaded synchronously, then you don't have to wait for them - they will load before any other scripts after them run.

提交回复
热议问题