Put Scripts at the Bottom
来源:互联网 发布:qt编程语言 编辑:程序博客网 时间:2024/06/10 20:43
将script放在页面最下面 (Put Scripts at the Bottom )
将脚本放在页面最下面的目的有那么两点: 1、 因为防止script脚本的执行阻塞页面的下载。在页面loading的过程中,当浏览器读到js执行语句的时候一定会把它全部解释完毕后在会接下来读下 面的内容。不信你可以写一个js死循环看看页面下面的东西还会不会出来。(setTimeout 和 setInterval的执行有点类似于多线程,在相应的响应时间之前也会继续下面的内容渲染。)浏览器这么做的逻辑是因为js随时可能执行 location.href或是其他可能完全中断此页面过程的函数,即如此,当然得等他执行完毕之后再加载咯。所以放在页面最后,可以有效减少页面可视 元素的加载时间。 2、脚本引起的第二个问题是它阻塞并行下载数量。HTTP/1.1规范建议浏览器每个主机的并行下载数不超过2个(IE只能为2个,其他浏览器如ff等都是默认设置为2个,不过新出的ie8可以达6个)。因此如果您把图像文件分布到多台机器的话,您可以达到超过2个的并行下载。但是当脚本文件下载时,浏览器不会启动其他的并行下载。
当然对各个网站来说,把脚本都放到页面底部加载的可行性还是值得商榷的。就比如阿里巴巴中文站的页面。很多地方有内联的js,页面的显示严重依赖于此,我承认这和无侵入脚本的理念相差甚远,但是很多“历史遗留问题”却不是那么容易解决的。
- Put Scripts at the Bottom
- Put Scripts at the Bottom .
- Android: Tabs at the bottom with FragmentTabHost
- Keep your footer show at the bottom of the page
- Customize UINavigationBar and remove drop shadow at the bottom of UINavigationBar
- 构建高性能网站的14条法则:Put Stylesheets at the Top
- Why do you need to put #!/bin/bash at the beginning of a script file?
- Kaldi-Running the example scripts
- PKU2553 the bottom of the graph
- Where to put the const?
- bottom
- ui page control and scrollview with indicator at bottom
- VI编辑器 Search it Bottom, Continuing at Top
- POJ 2553 The Bottom of A Graph
- poj 2553 The Bottom of a Graph
- poj2553 The Bottom of a Graph
- Computer Science from the Bottom Up
- poj 2553 The Bottom of a Graph
- C#采集数据类(转)
- 台资企业管理职的中英文称谓以及级别
- MySQL的一些注意事项
- asp播放器源码
- CMD命令
- Put Scripts at the Bottom
- SQL like相关通配符
- STL算法学习,小结如下:
- PAGEBASE
- 利用JavaScript实现简单的拖动层(只使用于IE)
- C# U盘操作
- tomcat启动(一)
- CSS:清除浮动的最优方法
- Page 的生命周期学习小结