Zombie异步加载多个JS文件

时间:2012-03-01 16:03:54

标签: javascript node.js jsdom zombie.js

尝试僵尸几个小时并且兴奋不已。唯一(begginner的运气?)问题是脚本似乎异步加载(这很酷)并按照下载的顺序执行(而不是按照“原始”HTML文件中提到的顺序执行)。我会解释一下:

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <script>alert($('body'))</script>
</head>

http://jsfiddle.net/viebel/GWYEj/ - 以下脚本加载jQuery并尝试使用它。下载jQuery需要时间,但Zombie似乎在下载完成之前进入下一个脚本部分。显然,没有jQuery对$('body')没有多大意义,因此我们得到以下错误:

Zombie: GET http://jsfiddle.net/viebel/GWYEj/show/
Zombie: GET http://jsfiddle.net/viebel/GWYEj/show/ => 200
Zombie: GET http://jsfiddle.net/js/lib/mootools-core-1.4.4.js
Zombie: GET http://code.jquery.com/jquery-1.7.1.js
Zombie: GET http://jsfiddle.net/js/lib/mootools-core-1.4.4.js => 200
Zombie: Unexpected token } SyntaxError: Unexpected token }
    at Object._evaluate (/home/viebel/node_modules/zombie/lib/zombie/browser.coffee:136:28)
    in http://jsfiddle.net/viebel/GWYEj/show/:undefined:undefined<script>
Zombie: GET http://code.jquery.com/jquery-1.7.1.js => 200

在“常规”浏览器中,代码可以流畅地工作。是的,我们知道node.js不是真正的客户端javascript,但Zombie.js应该是,不是吗?

请帮助我们做错了什么。

0 个答案:

没有答案
相关问题