tag:blogger.com,1999:blog-8980734269859237005.post138926035462404342..comments2024-01-30T01:03:21.768-08:00Comments on DevCurry: jQuery Add Elements Dynamically: Performance TipSuprotim Agarwalhttp://www.blogger.com/profile/08349831623922214390noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8980734269859237005.post-24743938528116796842011-10-20T03:27:15.618-07:002011-10-20T03:27:15.618-07:00Can you pl show how to load data into a gridview ...Can you pl show how to load data into a gridview using asp.net - jquery - ajax - json - db?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-59897283210050494072011-10-19T19:38:42.710-07:002011-10-19T19:38:42.710-07:00Anonymous - That's a very good point about sel...Anonymous - That's a very good point about selectors you made there. <br /><br />Alan - yes devs do exactly that. If the same element is to be generated, one can cache it and select the container using an 'id' if one if available. As anonymous pointed out, selectors help a great deal here.<br /><br />hughdbrown - yes probably. The best way to find is to run atleast 500 iterations and Suprotim Agarwalhttps://www.blogger.com/profile/08349831623922214390noreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-13288230029026662922011-10-19T18:39:13.208-07:002011-10-19T18:39:13.208-07:00I suspect you'd also get a good speed up if yo...I suspect you'd also get a good speed up if you put the strings into an array and concatenated them together once (as opposed to creating a new, immutable string each iteration).<br /><br />var segments = [];<br />for(var cnt=0; cnt < 200; cnt++){<br /> segments.push('< p >Lorem ipsum dolor sit amet');<br />}<br />$('.container').append(segments.join(''));Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-53890097200790018342011-10-19T14:35:25.627-07:002011-10-19T14:35:25.627-07:00Note that in the first example, your are repeating...Note that in the first example, your are repeating the $('.container') lookup as well as the Element.append() 200 times. From which of these is the majority of this time coming from?<br /><br />I suspect that you'd get a similar time speed-up by just calling $('.container') once and saving the result.Alan Kruegerhttps://www.blogger.com/profile/06185040120023302553noreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-45919254077435461772011-10-19T11:02:00.582-07:002011-10-19T11:02:00.582-07:00While caching the raw HTML in a variable is, gener...While caching the raw HTML in a variable is, generally, good advice, there's something off in the code provided: jQuery selectors.<br /><br />jQuery selectors, specially the ones like "fetch me any element with this class" are particularly slow, since they need to crawl over all the DOM.<br /><br />For an accurate comparison you should drop the selector from the first loop and use aAnonymousnoreply@blogger.com