所有inline< script>的加载之前或之后,$ .ready是否已启动? [英] Does $.ready fire before or after all inline <script>'s have been loaded?

查看:78
本文介绍了所有inline< script>的加载之前或之后,$ .ready是否已启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是一个例子:

 < html> 
< head>
< script src =waiting_on_ready.js/>
< / head>
< body>
< script src =http://somewhere.com/not_cached.js>< / script>
< / body>
< / html>

wait_on_ready.js中的$ .ready回调是否必须等待加载not_cached.js?是否等待执行not_cached.js?

解决方案

是和是。



当使用HTML5 < script> 元素是同步的, .wikipedia.org / wiki / Comparison_of_layout_engines_%28HTML5%29#属性rel =noreferrer>async属性。需要JavaScript的同步执行(除非另有要求),因为JavaScript可以通过 document.write 等修改文档流(但是,实际获取资源可能并行。)



快乐编码。


At the core, this is a javascript question but I'm interfacing the event with jQuery.

Here's an example case:

<html>
  <head>
    <script src="waiting_on_ready.js" />
  </head>
  <body>
    <script src="http://somewhere.com/not_cached.js"></script>
  </body>
</html>

Does the $.ready callback in waiting_on_ready.js have to wait for not_cached.js to be loaded? Does it wait for not_cached.js to be executed?

解决方案

Yes and yes.

The execution of <script> elements is synchronous except when using the HTML5 "async" attribute. The synchronous execution of JavaScript is required (unless otherwise requested not to be) because the JavaScript can modify the document stream through document.write, etc. (However, the actual fetching of resources may be in parallel.)

Happy coding.

这篇关于所有inline&lt; script&gt;的加载之前或之后,$ .ready是否已启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆