高性能JavaScript

本网站不提供下载链接,喜欢看书的朋友请关注公众号:【lennylee的碎碎念】(lennyleede),首页回复:授人以渔,自动获取搜索资源的方法。

内容简介:

如果你使用JavaScript构建交互丰富的Web应用,那么JavaScript代码可能是造成你的Web应用速度变慢的主要原因。《高性能JavaScript》揭示的技术和策略能帮助你在开发过程中消除性能瓶颈。你将会了解如何提升各方面的性能,包括代码的加载、运行、DOM交互、页面生存周期等。雅虎的前端工程师Nicholas C. Zakas和其他五位JavaScript专家介绍了页面代码加载的最佳方法和编程技巧,来帮助你编写更为高效和快速的代码。你还会了解到构建和部署文件到生产环境的最佳实践,以及有助于定位线上问题的工具。

作者简介:

Nicholas C.Zakas,雅虎首页的主要开发者,雅虎用户界面库(YUI)代码贡献者,擅长利用JavaScript、HTML、CSS、XML、XSLT设计和实现WEB界面的软件工程师。

前言
第1章 加载和执行
1.1 脚本位置
1.2 组织脚本
1.3 无阻塞的脚本
1.4 小结
第2章 数据访问
2.1 管理作用域
2.2 对象成员
2.3 小结
第3章 DOM编程
3.1 浏览器中的DOM
3.2 DOM访问与修改
3.3 重绘与重排
3.4 事件委托
3.5 小结
第4章 算法和流程控制
4.1 循环
4.2 条件语句
4.3 递归
4.4 小结
第5章 字符串和正则表达式
5.1 字符串连接
5.2 正则表达式优化
5.3 去除字符串首尾空白
5.4 小结
第6章 Responsive Interfaces
6.1 浏览器UI线程
6.2 使用定时器让出时间片段
6.3 Web Workers
6.4 小结
第7章 Ajax
7.1 数据传输
7.2 数据格式
7.3 Ajax性能指南
7.4 小结
第8章 编程实践
8.1 避免双重求值(Double Evaluation)
8.2 使用Object/Array直接量
8.3 不要重复工作
8.4 使用速度快的部分
8.5 小结
第9章 构建并部署高性能JavaScript应用
9.1 Apache Ant
9.2 合并多个JavaScript文件
9.3 预处理JavaScript文件
9.4 JavaScript压缩
9.5 构建时处理对比运行时处理
9.6 JavaScript的HTTP压缩
9.7 缓存JavaScript文件
9.8 处理缓存问题
9.9 使用内容分发网络(CDN)
9.10 部署JavaScript资源
9.11 敏捷JavaScript构建过程
9.12 小结
第10章 工具
10.1 JavaScript性能分析
10.2 YUI Profiler
10.3 匿名函数
10.4 Firebug
10.5 IE开发人员工具
10.6 Safari Web检查器(Web Inspector)
10.7 Chrome开发人员工具
10.8 脚本阻塞
10.9 Page Speed
10.10 Fiddler
10.11 YSlow
10.12 dynaTrace Ajax Edition
10.13 小结
索引
· · · · · · (收起)

原文摘录:

• Literal values and local variables can be accessed very quickly, whereas array items
and object members take longer.
• Local variables are faster to access than out-of-scope variables because they exist
in the first variable object of the scope chain. The further into the scope chain a
variable is, the longer it takes to access. Global variables are always the slowest to
access because they are always last in the scope chain.
• Avoid the with statement because it augments the execution context scope chain.
Also, be careful with the catch clause of a try-catch statement because it has the
same effect.
• Nested object members incur significant performance impact and should be
minimized.
• The deeper into the prototype chain that a property or method exists, the slower
it is to access.
• Ge… (查看原文)

寸志
2011-02-23 18:33:56

—— 引自第53页

• Minimize DOM access, and try to work as much as possible in JavaScript.
• Use local variables to store DOM references you’ll access repeatedly.
• Be careful when dealing with HTML collections because they represent the live,
underlying document. Cache the collection length into a variable and use it when
iterating, and make a copy of the collection into an array for heavy work on
collections.
• Use faster APIs when available, such as querySelectorAll() and
firstElementChild.
• Be mindful of repaints and reflows; batch style changes, manipulate the DOM tree
“offline,” and cache and minimize access to layout information.
• Position absolutely during animations, and use drag and drop proxies.
• Use event delegation to minimize the number of event handlers. (查看原文)

寸志
2011-02-23 20:58:51

—— 引自第79页