High Performance JavaScript

Nicholas C. Zakas

出版时间

2010-04-02

ISBN

9780596802790

评分

★★★★★
书籍介绍
这本书最耐人寻味的地方,在于它是一份带着时代烙印的'性能考古'。它把JavaScript引擎内部的运作机制掰开揉碎:为什么局部变量比全局变量快,为什么with语句和catch子句会拖慢作用域链,为什么原型链越深访问越慢。这些'为什么'至今仍是理解JS运行原理的钥匙。但读者也毫不留情地指出:作为2010年的作品,书中大量针对旧版浏览器的技巧(如特定事件触发时机)如今已需重新审视,核心语言性能部分更被评价为'过时'。因此它真正的价值不在'照做',而在帮你建立判断力——理解引擎为何如此,从而在纷繁的新技巧中分辨什么经得起时间考验。适合想追根溯源、而非只背优化清单的开发者。
AI导读
核心看点
  • 系统讲解JS加载、执行、DOM操作及页面生命周期优化策略
  • 揭示变量访问速度差异,强调局部变量优于全局变量
  • 提供脱离文档流修改DOM、惰性加载等具体性能调优技巧
读者共识
  • 被誉为前端性能优化领域的经典神书,实战价值极高
  • 内容精炼字字如金,虽部分技术过时但核心思想永不过时
  • 适合配合《JS高级程序设计》阅读,深化对语言机制理解
精彩摘录
  • "• 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"
用户评论
必备基础
小脚本,大世界
现在是2013年,刚花了几个小时把这本书通读了一遍。书很薄,内容很直白,读起来飞快。可以想像就2010年的时间点来说这本书里很多建议挺靠谱的。但如果它今天再版的话,很多内容恐怕都要修正了,特别是关于JavaScript核心语言性能的部分。而且总觉得这书有些细节上技术术语用词不准确⋯不过不影响大的主题,问题不大。
这是看过的最好的javascript的书,没有之一。Chapter2: Data access最重要。
JS本身的执行效率没什么好担心的. 前端性能优化还是 Steve Souders 的两本书更有价值. 而这些最佳实践也都已经充分传播开来了.
读完了,虽然文章末的工具已经很老了,不过整体上来说绝绝子。 作者对每个概念进行内存和性能方面的分析的图表令人印象深刻,且讲解鞭辟入里,案例也很棒,赞👍🏻
搭配 jsperf.com 服用。F2E 居家必备。
很棒的书,但因为比较久了,里面大部分内容已经不再适用了。
即使从 分析 角度来说,也是好书。Analysing &amp; profiling: algorithms, language statements, DOM, render, I/O, parallels, cache, regex &amp; XML etc.
5年里JS界早换了模样 还是涨了一些姿势
下载
收藏