最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Does $.ready fire before or after all inline <script>'s have been loaded? - Stack Overflow

programmeradmin0浏览0评论

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=".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?

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?

Share Improve this question asked Jun 1, 2011 at 1:14 AaronAaron 8392 gold badges9 silver badges16 bronze badges 2
  • 1 may be you can put an alert and try – zod Commented Jun 1, 2011 at 1:21
  • stackoverflow.com/questions/1213281/… – zod Commented Jun 1, 2011 at 1:21
Add a comment  | 

4 Answers 4

Reset to default 10

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.

Ready fires when all DOM elements are ready for manipulation.

When the browser comes across a script element, DOM parsing stops until the script has been executed, so because of how it all works, it fires after all scripts are loaded.

$(document).ready() would not be triggered prior to not_cached.js to be loaded and executed (assuming execution in not_chached.js is synchronous)

the $.ready script executes after the page is fully loaded, as the onload event does, however if an inline script is found then it is executed.

发布评论

评论列表(0)

  1. 暂无评论