[jQuery] Re: window unload event too slow - delay when navigate away from the page

2009-03-25 Thread johan . borestad

Hi!
If you have a lot of selectors, you should probably use Event
Delegation and wait for the event to bubble instead.
A good example is if you have a huge table and events on every row.
Instead of using $('table a').bind('click', function(){ alert('do
stuff!!') }) , you just bind ONE event on the table and listens for
all other events to happen (like click/mouseover/focus etc).

You may want to look at the new jQuery feature jQuery.live()
http://docs.jquery.com/Events/live

A very good plugin (I use it myself in some really huge projects) that
also solves a bug where IE6 doesn't bubble focus/blur events on some
elements is jquery.listen
http://plugins.jquery.com/project/Listen

Read more about Event delegation from here :)
http://www.google.se/search?hl=svq=event+delegation+javascriptbtnG=Google-s%C3%B6kningmeta=aq=0oq=

/ Johan


On 25 Mar, 05:42, Khoa nvkho...@gmail.com wrote:
 One of the pages I'm working on at the moment is quite big, it has a
 huge amount of HTML elements and many of them have events bound to
 them. So whenever I navigate out of that page, there is a huge delay.
 The browser seems to be freezing during that time. And then it loads
 the next page (the page that I go to).

 I notice that, this is because of the window unload event, which is
 specified in the source code at:

 jQuery( window ).bind( 'unload', function(){
         for ( var id in jQuery.cache )
                 // Skip the window
                 if ( id != 1  jQuery.cache[ id ].handle )
                         jQuery.event.remove( jQuery.cache[ id ].handle.elem );

 });

 Is there anyway that we can speed up this event? Maybe in the next
 release of jQuery? This snippet seems to take too much time to run on
 large page. If there is not, can I just remove it? Why do we need this
 function? Sorry, I'm still new to JS, so I'm don't know why we need
 this, please advise.

 Thanks.


[jQuery] Re: window unload event too slow - delay when navigate away from the page

2009-03-25 Thread johan . borestad

Typo error above, a lot of selectors should be a lot of events