JavaScript作为(根据萤火虫)在Firefox 3中异步加载? [英] JavaScript being loaded asynchronously in Firefox 3 (according to Firebug)?

查看:193
本文介绍了JavaScript作为(根据萤火虫)在Firefox 3中异步加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来分析一个网站,我相当有信心通过JavaScript文件的网页上加载正在放缓的性能。

I'm trying to profile the performance of a web site that I'm fairly confident is being slowed down by the loading of JavaScript files on the page.

同样的JavaScript文件都包含在页面上几次,<脚本/> 标签散布在页面而不是被的包括在底部

The same JavaScript files are included several times on the page, and <script /> tags are scattered throughout the page instead of being included at the bottom.

正如我怀疑,看着Firebug的网络选项卡的时候,大部分时间(不是全部),当被加载的JavaScript,没有其​​他文件要求。浏览器等待JavaScript完成加载。

As I suspected, when looking at FireBug's "Net" tab, most of the time (not all) when JavaScript is being loaded, no other files are requested. The browser waits for the JavaScript to complete loading.

有然而少数例外。存在其中JavaScript是装载有几次,但随后在同一时间,其他资源出现得到加载,如其他​​JavaScript文件和图像。

There are a few exceptions however. There are a few occasions where JavaScript is loaded, but then at the same time, other resources appear to get loaded, such as other JavaScript files and images.

我一直以为页面上的其他资源的JavaScript块的加载。我在想这不正确,还是这种行为取决于浏览器或浏览器版本有什么不同?

I always thought that JavaScript blocks the loading of other resources on the page. Am I incorrect in thinking this, or does this behavior vary depending on the browser or browser version?

更新:

对于那些谁也解释了如何加载脚本阻止其他资源的加载,我已经意识到这一点。我的问题是,为什么一个脚本的不会阻止其他资源的加载。 Firebug是显示出一些JavaScript文件的不要块加载其他资源。我想知道为什么会发生这种事。

UPDATE:
To those who have explained how loading a script blocks the loading of other resources, I'm already aware of this. My question is why a script wouldn't block the loading of other resources. Firebug is showing that some JavaScript files do not block loading other resources. I want to know why this would happen.

推荐答案

的Javascript资源请求确实阻挡,但也有办法解决这个(即:在头部DOM注入脚本标签和AJAX请求),它没有看到页面自己很可能是这里发生了什么。

Javascript resource requests are indeed blocking, but there are ways around this (to wit: DOM injected script tags in the head, and AJAX requests) which without seeing the page myself is likely to be what's happening here.

包括相同的JS资源的多个副本是的极坏的但不一定是致命的,而且是典型的可能是从不同的团队的工作增生较大的网站,或者只是普通的老坏的编码,规划,或维护。

Including multiple copies of the same JS resource is extremely bad but not necessarily fatal, and is typical of larger sites which might have been accreted from the work of separate teams, or just plain old bad coding, planning, or maintenance.

至于雅虎的建议,在主体的底部放置的脚本,这提高的 percieved 的响应时间,并能提高实际负荷倍的程度(因为所有的previous资源允许异步第一),但它永远不会是非阻塞请求作为有效的(尽管他们与技术能力的高阻隔)。

As far as yahoo's recommendation to place scripts at the bottom of the body, this improves percieved response times, and can improve actual loading times to a degree (because all the previous resources are allowed to async first), but it will never be as effective as non-blocking requests (though they come with a high barrier of technical capability).

pretty无阻塞JS 这里体面讨论

Pretty decent discussion of non-blocking JS here.

这篇关于JavaScript作为(根据萤火虫)在Firefox 3中异步加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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