Skip to content

Instantly share code, notes, and snippets.

@a1exlism
Created March 15, 2018 15:53
Show Gist options
  • Save a1exlism/1df1a59dd1edceb46dccdb4f64839b52 to your computer and use it in GitHub Desktop.
Save a1exlism/1df1a59dd1edceb46dccdb4f64839b52 to your computer and use it in GitHub Desktop.
/*
* ul insert 1000 li tag
*/
let ul = document.querySelectorAll('.list');
console.time('no frag');
for(let i = 0; i < 1000; ++i) {
let li = document.createElement('li');
li.textContent = 'No ' + i;
ul[0].appendChild(li);
}
console.timeEnd('no frag');
console.time('with frag');
let tmpLilist = document.createDocumentFragment();
for(let i = 0; i < 1000; ++i) {
let li = document.createElement('li');
li.textContent = 'No ' + i;
tmpLilist.appendChild(li);
}
ul[1].appendChild(tmpLilist);
console.timeEnd('with frag');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment