Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to efficiently append content with JQuery

I am using JQuery to append large amounts of text inside a tag. I find the more text currently within the tag the slower appending is, and for large amounts of text it is too slow.

Is there a more efficient way to append text? Such as for instance creating dummy child tags and setting the content of them rather than appending to the parent?

like image 345
hoju Avatar asked Jan 18 '26 06:01

hoju


2 Answers

Check this presentation and this one too: jQuery Anti-Patterns
And in general:

  • do not .append() in loop
  • do not append directly into DOM
  • build a string and than append it or use DocumentFragment
  • do not append directly into DOM
like image 85
NilColor Avatar answered Jan 20 '26 20:01

NilColor


Use DOM DocumentFragments to append a bunch a node, and take a look on Nicholas Zakas presentation in slideshare "writing-efficient-javascript"

like image 34
wharsojo Avatar answered Jan 20 '26 20:01

wharsojo