Created
November 22, 2013 17:50
-
-
Save markmarkoh/7604037 to your computer and use it in GitHub Desktop.
Making slow DOM based operations faster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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