Skip to content

Instantly share code, notes, and snippets.

@sindre
Created May 9, 2011 07:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sindre/962201 to your computer and use it in GitHub Desktop.
Save sindre/962201 to your computer and use it in GitHub Desktop.
JS createDocumentFragment to avoid reflow
// http://www.slideshare.net/nzakas/high-performance-javascript-amazon-devcon-2011
var list = document.getElementsByClassName('items')[0],
fragment = document.createDocumentFragment(),
i, item;
for (i=0; i < 10; i++) {
item = document.createElement('li');
item.innerHTML = 'item #'+i;
fragment.appenChild(item);
}
list.appenChild(fragment);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment