高性能JavaScript

Nicholas C.Zakas

出版时间

2010-11-01

ISBN

9787121119323

评分

★★★★★

标签

编程

书籍介绍
这不像一本教你'怎么写JS'的书,而像一份前端工程师的'排雷手册'。它把'慢'拆成一个个具体可查的环节:作用域链里变量离得越远访问越慢、原型链爬得越深开销越大、HTML集合是活的所以遍历要当心、重排重绘能攒则攒。书里那些近乎偏执的技巧——缓存对象成员、让元素脱离文档流、用事件委托减少监听器——读起来常让人'回到C语言':为一点点性能反复较真。它真正打动人的地方,是让你养成'对每一次访问都心存怀疑'的习惯。适合那些已经能写出能跑的代码、却想知道'为什么用户就是觉得卡'的开发者。唯一被反复提及的缺憾是:成书已逾三年,没有第二版,部分结论需结合新浏览器自行判断。
作者简介
Nicholas C.Zakas,雅虎首页的主要开发者,雅虎用户界面库(YUI)代码贡献者,擅长利用JavaScript、HTML、CSS、XML、XSLT设计和实现WEB界面的软件工程师。
AI导读
核心看点
  • 系统解析JS加载、执行、DOM交互等全链路性能优化策略。
  • 深入剖析作用域链、原型链及数据访问对运行效率的影响。
  • 提供最小化重排、事件委托及算法优化的具体实战技巧。
读者共识
  • 被誉为前端性能优化领域的经典神书,干货密度极高。
  • 作者基于大量测试数据总结经验,观点科学且极具说服力。
  • 虽出版较早,但其核心编程思想与优化理念至今仍具价值。
精彩摘录
  • "• 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"
  • "• 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 "
  • "1. 使元素脱离文档流 2. 对其应用多重改变 3. 把元素带回文档中 有三种基本方法可以使 DOM 脱离文档: - 隐藏元素,应用修改,重新显示 - 使用文档片段(document fragment)在当前 DOM 之外构建一个子树,再把它拷贝回文档 - 将原始元素拷贝到一个脱离文档的节点中,修改副本,完成后再替换原始元素"
  • "一个长度为 n 的数组最终会调用 mergeSort() 2*n-1 次,这意味着一个长度超过 1500 的数组会在 Firefox 上发生栈溢出错误。"
  • "One word of caution: it is not recommended to use this technique for object methods. Many object methods use this to determine the context in which they are being called, and storing a method in a local variable causes this to be bound to window. Changing the value of this leads to programmatic erro"
  • "Firefox, Opera, Chrome, and Safari 3+ all fire a load event when the src of a <script> element has been retrieved. You can therefore be notified when the script is ready by listening for this event:"
  • "If you only care about sending data to the server (with possibly a very simple response), use image beacons. Beacons are the fastest and most efficient way to send data back to the server. The server doesn’t have to send back any response body at all, so you don’t have to worry about downloading dat"
  • "These two functions implement a lazy-loading pattern. The first time either method is called, a check is made to determine the appropriate way to attach or detach the event handler. Then, the original function is overwritten with a new function that contains just the appropriate course of action. Th"
目录
前言 1
第1章:加载和执行 1
1.1 脚本位置 2
1.2 组织脚本 4
1.3 无阻塞的脚本 5

显示全部
用户评论
薄薄的一本,涉及的面不少,属于释义多 案例少的类型,最喜欢最后放上一堆小工具啦 可以提高调试效率和填充边缘信息面
翻
只能说YUI还是NB
优化的几个思路:1.变量和数据的访问;2. 选择性能高的DOM方法,及把DOM操作尽量整合到一次完成;3.优化for循环和ifelse条件判断;4.优化字符串郑泽操作;5.用定时器控制ui进程之行栈;6.选择合适的传输类型(json轻量html节省dom效率),用state==3分段解析;7.不要执行字符串,用[],{}直接量,去掉重复的如判断操作;8.压缩合并缓存;9.利用一些性能工具
看了几页了,翻译的不怎么地,没几页就找出好几个错误,不知道后面的内容怎么样
内容些许过时,但是思想贯通的。
读这本书的前提是你已经有一定的js基础,并且写过一些简单项目. 读完后会有一种茅塞顿开的感觉
10 年前的书现在看确实过时了些,不过还是可以学到点的
非常值得看的一本书,虽然时间有点久了,但是还是非常有价值
下载
收藏