Skip to content

Instantly share code, notes, and snippets.

@markmarkoh
Created November 22, 2013 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmarkoh/7604037 to your computer and use it in GitHub Desktop.
Save markmarkoh/7604037 to your computer and use it in GitHub Desktop.
Making slow DOM based operations faster
//slow on a large enough collection ( > ~50 )
var self = this;
collectionData.each(function(model) {
self.$el.append( model.get("name") );
});
//to make it fast again, you can create an element in memory and operate on that
var $inMemoryjQueryElement = $("<div/>");
collectionData.each(function(model) {
$inMemoryjQueryElement.append( model.get("name") );
});
//and then only touch the actual DOM once
this.$el.append( $inMemoryjQueryElement );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment