Web-side when a large number of DOM data insertion, if a one-time insertion of thousands of data, the browser will be unable to appear in the case of the death of Kaka, the code is as follows:
vararr = []; for(vari = 0; i < 1000; i++) {Arr.push (i);}varLoadData =function(data) { for(vari = 0, L = data.length; I < L; i++){ varElem = document.createelement (' div '); Div.innerhtml=i; Document.body.appendChild (DIV); }};loaddata (arr);//Create a Timechunk () function to insert the DOM in batchesvarTimechunk =function(Data, FN, count, interval) {)//Data data fn Execution logic function count one-time number of insertions interval batch execution varobj,t; varLen =arr.length; varStart =function(){ for(vari = 0; I < Math.min (Count | | 1, arr.length), i++){ varobj =Arr.shift (); fn (obj); } }; return function() {T= SetInterval (function(){ if(Arr.length = = 0){ returnclearinterval (t); }}, Interval)}}
JavaScript Design Patterns and development practices: time-sharing functions