Monthly Archives: October 2012

dom tree traversal

type=”text/javascript”>   function htmlTree(obj){     var obj = obj || document.getElementsByTagName(‘body’)[0];     var str = ” ” + obj.tagName;     if (obj.hasChildNodes()) {       var child = obj.firstChild;       while (child) {         if (child.nodeType === 1) {           str … Continue reading

Posted in Uncategorized | Leave a comment

front end optimization

(1) 减少http请求次数:css spirit,data uri (2) JS,CSS源码压缩 (3) 前端模板 JS+数据,减少由于HTML标签导致的带宽浪费,前端用变量保存AJAX请求结果,每次操作本地变量,不用请求,减少请求次数 (4) 用innerHTML代替DOM操作,减少DOM操作次数,优化javascript性能 (5) 用setTimeout来避免页面失去响应 (6) 用hash-table来优化查找 (7) 当需要设置的样式很多时设置className而不是直接操作style (8) 少用全局变量 (9) 缓存DOM节点查找的结果 (10) 避免使用CSS Expression (11) 图片预载 (12) 避免在页面的主体布局中使用table,table要等其中的内容完全下载之后才会显示出来,显示比div+css布局慢 32,如何控制网页在网络传输过程中的数据量 启用GZIP压缩 保持良好的编程习惯,避免重复的CSS,JavaScript代码,多余的HTML标签和属性

Posted in front end | Leave a comment

John Resig – getElementsByClassName Speed Comparison

http://ejohn.org/blog/getelementsbyclassname-speed-comparison/

Posted in Uncategorized | Tagged | Leave a comment

Document Object Model Traversal

http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html

Posted in Uncategorized | Tagged | Leave a comment

Javascript – Traversing the HTML DOM recursively « blog.swapnilsarwe.com

http://blog.swapnilsarwe.com/javascript-traversing-html-dom-recursively.html

Posted in algorithm | Tagged | Leave a comment

3sum issue

public class Solution {    public ArrayList<ArrayList<Integer>> threeSum(int[] num) {        // Start typing your Java solution below        // DO NOT write main() function        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();        if( num == null || num.length == 0 )        {            return result;        }        … Continue reading

Posted in Uncategorized | Tagged | Leave a comment

javascript bind

Method = ( function() { return { bind : function( method, context ) { var argCopy = []; for( i = 2; i arguments.length; i++ ) { argCopy.push( arguments[i] ); } method.apply( context, argCopy ); } }; } )(); Package … Continue reading

Posted in front end | Tagged , | Leave a comment