高性能JavaScript - Nicholas C.Zakas

高性能JavaScript

Nicholas C.Zakas

出版时间

2010-11-01

ISBN

9787121119323

评分

★★★★★

标签

编程

书籍介绍

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

AI导读
核心看点
  • 系统解析JS加载、执行、DOM交互等全链路性能优化策略。
  • 深入剖析作用域链、原型链及数据访问对运行效率的影响。
  • 提供最小化重排、事件委托及算法优化的具体实战技巧。
适合谁读
  • 致力于提升Web应用响应速度与用户体验的前端开发工程师。
  • 希望深入理解浏览器渲染机制及JS底层运行原理的开发者。
  • 寻求构建高效、可维护且高性能JavaScript代码的程序员。
读前提醒
  • 部分早期浏览器兼容技巧已过时,需结合现代环境辩证阅读。
  • 建议配合原版对照阅读,以规避中文版存在的翻译瑕疵问题。
  • 书中部分极致优化技巧较晦涩,建议结合实战代码反复体会。
读者共识
  • 被誉为前端性能优化领域的经典神书,干货密度极高。
  • 作者基于大量测试数据总结经验,观点科学且极具说服力。
  • 虽出版较早,但其核心编程思想与优化理念至今仍具价值。

本导读基于书籍简介、目录、原文摘录、短评和书评生成,不等同于全文精读。

精彩摘录
  • "• 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"
作者简介
Nicholas C.Zakas,雅虎首页的主要开发者,雅虎用户界面库(YUI)代码贡献者,擅长利用JavaScript、HTML、CSS、XML、XSLT设计和实现WEB界面的软件工程师。
目录
前言 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 年前的书现在看确实过时了些,不过还是可以学到点的
非常值得看的一本书,虽然时间有点久了,但是还是非常有价值
下载
收藏