Efficient JavaScript coding
1, 尽可能选择高效的method
e.g.
如果没有必要,可以不用regular expression
String.indexOf, String.lastIndexOf > String.match, String.search, String.replace
2, 面对large loop就要斤斤计较
2.1 Create once, use repeatedly
for( var i = 0, oNode; oNode = oElement.childNodes[i]; i++ ) {
if( oNode.nodeValue.match(/^\s*extra.*free/g) ) {
//this creates the expression
//it will be cached and re-used next time through the loop
}
}
for( var i = 0, oNode; oNode = oElement.childNodes[i]; i++ ) {
if( oNode.nodeValue.match(new RegExp(“^\s*extra.*free”,”g”)) ) {
//this will always create a new copy of the expression,
//and is generally much slower than creating static expressions.
}
}
2.2 Referencing element once, use repeatedly
var _table =$("#tableId")
for (var index in json) {
otherFun(_table, json[index]);
};
3 eval is evil
Eval 或者 new Function() 执行时,浏览器先创建整个scripting环境(就像一个新页面),导入scope chain中所有变量,执行script,gc, 最后导出所有变量到当前环境。(in a word, cost much)另外,js engine还不能对它们进行cache优化。
4 less is more
Less code, short naming
Only add event listener what you need
5 do less
Take a short circuit
e.g
var logger=window.console && window.console.dir
var logger=window.console || {}
less XHR calling
e.g. enable cache for the same request
6 Reduce reflow
每当添加element到document里,browser就会reflow整个页面去计算如何重新定位和渲染。
7,cache
Enable cache for duplicated XHR calling
Enable cache for js script file, so move out jscript from jsp to js file.
Reference:
http://slowjavascript.com/JavaScript_Performance_Rocks_Checklist.pdf
分享到:
相关推荐
详尽的代码规范, 2008.10月版, 约40页PDF
Efficient sparse coding algorithms对应源码,L1-norm约束
Efficient CC++ Coding Techniques,同事给的,还没有来得及看
Verilog Coding Style for Efficient Digital Design Verilog英文教材
efficient variant of huffman coding in high level languages
We prove that applying ideas from network coding allows to realize significant benefits in terms of energy efficiency for the problem of broadcasting, and propose very simple algorithms that allow to ...
Apply design patterns to solve JavaScript coding problems Learn coding patterns that unleash the unique power of the language Write better and more maintainable JavaScript code Type in and play around...
Efficient Message Composition and Coding for Cooperative Vehicular Safety Applications
很好的JavaScript入门书,强烈推荐,源码可以在这个网址...✓✓Working with JavaScript Objects✓✓Using advanced JavaScript techniques, such as AJAX, callbacks, and closures ✓✓Getting started with jQuery
This book helps you answer that question with numerous JavaScript coding patterns and best practices. If you're an experienced developer looking to solve problems related to objects, functions, ...
This book is an exploration of popular advanced JavaScript concepts for those who already have a grasp on the basics....- Writing Fast, Memory-Efficient JavaScript - Designing Better JavaScript APIs
Bruno A.Olshausen的经典稀疏编码matlab代码,文章是1996年LETTERS TO NATURE上的emergence of simple-cell receptive field properties by learning a sparse code for natural images.
Along the way you’ll discover how to create your own libraries and APIs for even more efficient coding., * Master the basics of object-oriented programming in JavaScript, as they apply to design ...
What's the best approach for developing an application with JavaScript? This book helps you answer that question with numerous JavaScript coding patterns and best practices.
NULL 博文链接:https://johnson-gong.iteye.com/blog/2144783
using JavaScript and p5.js and secondarily in creating visuals. The main focus is to teach you how to program so that you can choose to pursue whatever field that you would like with your newly ...
Pro JavaScript Development is a practical guide for front-end web developers who are ... Become a master of the latest JavaScript coding techniques and tools, and harness its best capabilities today.
Contrastive Multiview Coding笔记
opencores_coding_guidelines.pdf. RTL_coding_hints.pdf simul-mismatch.pdf Talk about BiT length .pdf
Get Coding! Learn HTML, CSS & JavaScript & Build a Website, App & Game 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...