简体   繁体   English

跨浏览器,同步,动态加载脚本

[英]Cross-browser, synchronous, dynamic loading of script

I need a way to dynamically load a JS file synchronously. 我需要一种同步动态加载JS文件的方法。

My thought was to make an XHR request for the script (which in this case is CDN dojo) but I run into the cross domain origin policy issue. 我的想法是向脚本发出XHR请求(在本例中为CDN dojo),但遇到了跨域源策略问题。 Any suggestions would be huge. 任何建议将是巨大的。 Thanks! 谢谢!

I'd suggest you try another approach rather than having them load synchronously. 我建议您尝试另一种方法,而不是让它们同步加载。 Most, if not all, script loaders load scripts asynchronously due to the nature of how they load them (dynamic script tags). 大多数(如果不是全部)脚本加载器由于其加载方式(动态脚本标签)的性质而异步加载脚本。

I suggest you take a look at module loaders like RequreJS 我建议您看一下RequreJS之类的模块加载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM