JavaScript in browsers is "single-threaded" (and thank goodness for that). So when JavaScript is running (in most browsers) everything else is queuing up. When you break the code into chunks, via setTimeout, you are (essentially) "yielding" control back to the main event loop periodically, so it has time to "breath" and clear it various queues.
Karl Rudd On Wed, Apr 2, 2008 at 8:04 PM, az <[EMAIL PROTECTED]> wrote: > > Thanks to both Karls for your help! > > I'll definitely try out the chunking method. Since I'd like to > understand what I'm implementing, can you briefly explain why this way > is better? > > thanks, > az > > > > On Apr 1, 4:59 pm, "Karl Rudd" <[EMAIL PROTECTED]> wrote: > > You can initialise the tips in "chunks". > > > > Instead of doing something like this: > > > > $('a.tip').cluetip(); > > > > Do something like this: > > > > $('a.tip').each(function() { > > var t = $(this); > > setTimeout( function() { t.cluetip(); }, 10 ); > > > > }) > > > > You'll still have a bit of a CPU usage spike but it shouldn't totally > > freeze the browser or bring up the "Running too long" type warnings. > > > > Karl Rudd > > > > > > On Tue, Apr 1, 2008 at 12:38 PM, az <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > > > I have a dynamically generated page that can be long or short. > > > Everything is fine when it's short, but when it gets to be *very* > > > long, it gives unresponsive script errors. > > > > > I believe this is because each entry on the page contains 3 clueTip > > > links. If I have a thousand entries, that's 3,000 clueTips to bind > > > and possibly keep in memory and then unbind when the user leaves the > > > page. That's a lot! > > > > > Any suggestions on how to prevent these errors? > > > > > My only thought is that instead of using jquery to bind the clueTips > > > at page load, I can do things the old-fashioned way and trigger the > > > clueTip by linking to a javascript function. > > > Something like: > > > <a href='javascript:clueTipFunction()'>link</a> > > > > > Will that work? > > > > > thanks, > > > az >