把Javascript脚本放到页面的底部的好处

[size=medium]转自:http://developer.yahoo.com/performance/rules.html#js_bottom

Put Scripts at the Bottom

tag: javascript
[size=x-small]
The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.[/size]

(google 翻译)
脚本所造成的问题是,他们阻止并行下载。 HTTP/1.1规范建议浏览器不超过两部分组成,每个主机的并行下载。如果您的图片,从多个主机服务,你可以得到两个以上的下载发生在平行。然而,当一个脚本下载,浏览器不会启动任何其他下载,甚至在不同的主机名。

In some situations it's not easy to move scripts to the bottom. If, for example, the script uses document.write to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to workaround these situations.
在某些情况下它是不容易移动脚本的底部。例如,如果脚本使用document.write来插入页面的内容的一部分,它可以不会被移到在页面低。还可能有范围的问题。在许多情况下,有办法要解决这些情况。

An alternative suggestion that often comes up is to use deferred scripts. The DEFER attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. Unfortunately, Firefox doesn't support the DEFER attribute. In Internet Explorer, the script may be deferred, but not as much as desired. If a script can be deferred, it can also be moved to the bottom of the page. That will make your web pages load faster.


常常会出现另一种建议是使用递延脚本。 defer属性表示脚本不包含文件撰写,是一个线索,他们可以继续渲染的浏览器。不幸的是,Firefox不支持defer属性。在Internet Explorer中,脚本可能会被推迟,但没有那么多需要。如果脚本可以被推迟,它也可以被移动到页面底部。这将使您的网页加载速度更快


[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值