I have application that brings response via Ajax and creates 5-20 new jQuery click listeners on each refresh. Both IE and mozilla browsers seem to be slowing down with usage. Can this slow down browser performance significantly. Can listeners be "released"?
Listeners set using .bind()
are released when the element is removed or .unbind()
ed. Those set using .live()
persist until you call .die()
or the element they are bound to is removed (which may be somewhere in the DOM if you specify, otherwise it'll default to the DOM root - .live()
works by not binding to the target element so the element can be removed/replaced/updated and the event listeners are still bound).
5-20 listeners sounds a few too many - consider binding less handlers if possible as older browsers will crack under the pressure far quicker than newer ones.