[jQuery] Re: help optimizing code

2008-01-20 Thread timothytoe
On Jan 19, 6:39 pm, cjl <[EMAIL PROTECTED]> wrote: > Karl: > > Thanks again. One last bug in the code you posted above, in the $ > ('div.flag').each function, the assignment: > > var $this = $(this); > > Needs to take place before the if-else statements. > > Overall, you improved code runs in ap

[jQuery] Re: help optimizing code

2008-01-19 Thread Karl Swedberg
On Jan 19, 2008, at 9:39 PM, cjl wrote: Karl: Thanks again. One last bug in the code you posted above, in the $ ('div.flag').each function, the assignment: var $this = $(this); Needs to take place before the if-else statements. Oops. Right. Good catch. :-) Overall, you improved code r

[jQuery] Re: help optimizing code

2008-01-19 Thread cjl
Karl: Thanks again. One last bug in the code you posted above, in the $ ('div.flag').each function, the assignment: var $this = $(this); Needs to take place before the if-else statements. Overall, you improved code runs in approximately 1 second...down from 4 seconds for my original code. Wow!

[jQuery] Re: help optimizing code

2008-01-19 Thread timothytoe
If Firebug is new to you, you're about to fall in love. Be sure to check out the various online tutorials. On Jan 19, 5:03 pm, cjl <[EMAIL PROTECTED]> wrote: > Also, TT, thank you, firebug is exactly what I was looking for! > > -CJL

[jQuery] Re: help optimizing code

2008-01-19 Thread Karl Swedberg
On Jan 19, 2008, at 8:03 PM, cjl wrote: Karl et al: Thank you for you helpful replies. I'm trying to understand the above code example provided by Karl: var $flag = $('').insertBefore('p'); $flag.each(function (i) { ... I'm not sure this works? Is this supposed to be equivalent to: $("

[jQuery] Re: help optimizing code

2008-01-19 Thread cjl
Karl et al: Thank you for you helpful replies. I'm trying to understand the above code example provided by Karl: var $flag = $('').insertBefore('p'); $flag.each(function (i) { ... I'm not sure this works? Is this supposed to be equivalent to: $("p").before(""); $(".flag").each(function (i

[jQuery] Re: help optimizing code

2008-01-19 Thread timothytoe
Have you tried Firebug's profiler? That's what I use. On Jan 19, 12:39 pm, cjl <[EMAIL PROTECTED]> wrote: > Is there any way to 'profile' the javascript as I try to optimize it, > to find out where the slow bits are? > -CJL

[jQuery] Re: help optimizing code

2008-01-19 Thread cjl
Thank you for your reply. I could do more on the server side, I'm guessing that python on the server will run faster than javascript in the browser. Chaining the selectors was a very good tip, and does seem to speed things up a little bit. Is there any way to 'profile' the javascript as I try t

[jQuery] Re: help optimizing code

2008-01-19 Thread Karl Swedberg
Here are a few ideas. Not sure how much this will help, but worth a shot... 1. put selectors that are used more than once into variables 2. rather than a bare class, use a tag name when possible in your selectors 3. instead of using string concatenation to build a DOM structure, use an ar

[jQuery] Re: help optimizing code

2008-01-19 Thread polyrhythmic
CJL, For 109 paragraphs, rewriting the HTML may always be slow, depending on the client. You could have $(document).ready put up a 'loading...' message and then launch a setTimeout, and have your DOM-manipulation code run after 500ms or so, whatever's long enough to get the page to display. $(d