Bug Tracker

Opened 15 years ago

Closed 15 years ago

#2298 closed bug (duplicate)

global ajax events can be slow if lots of DOM elements

Reported by: davidserduke Owned by:
Priority: major Milestone: 1.3
Component: ajax Version: 1.2.2
Keywords: Cc:
Blocked by: Blocking:


If there are lots of DOM elements, the global ajax events can be very slow. See related topic:


I was thinking it might make sense to allow the coder to override the "global" nature of the ajax events by passing in a selector. Perhaps something like this:

$.ajaxSetup({ global:".global_event_elem" });

So instead of sending the global events to all elements it would just go to those specific ones in the selector.

I put together a possible patch that is completely untested.

Attachments (1)

2298.diff (2.2 KB) - added by davidserduke 15 years ago.
untested patch (for the idea)

Download all attachments as: .zip

Change History (8)

Changed 15 years ago by davidserduke

Attachment: 2298.diff added

untested patch (for the idea)

comment:1 Changed 15 years ago by davidserduke

Component: coreajax

comment:2 Changed 15 years ago by flesler

I think this can only be solved by improving global event triggering, or disabling it... My app got stuck for 40 seconds everytime I used $.ajax, because of these events.

comment:3 Changed 15 years ago by davidserduke


What did you think about the patch I created? Did you try it out? Of course, as I said, it is untested but the theory seems sound. It would allow "global" triggering to be specific to an expression. I'd think that would be sufficient for a large dom.

comment:4 Changed 15 years ago by flesler

IMO, we need to go backwards a bit, and keep an array of dom elements, for each event. So global triggering will be fast and focused. Those arrays can always be nullified on window.unload along with the global unbind that we now have. I don't want to be... negative, but I think that global triggering, like this, is completely useless and I personally evade it.

comment:5 Changed 15 years ago by davidserduke

Did you look at the patch? Why do you think it would be slow? Since you could put any selector in there you could even do something like

$.ajaxSetup({ global:"#globalajaxwatcher" });

I might be missing something but I don't follow your logic. Even if the DOM had thousands of elements I'd think that would be very fast.

comment:6 Changed 15 years ago by flesler

Ah, didn't understand it before. This approach forces the user to maintain a selector that matches all the dom elements that have ajax events bound, this already seems to go in the wrong direction.

IMO, if we're already storing dom elements (can leak) in the handlers (.elem), then keeping an array(or map) for each event seems to me like the best approach.

Also bear in mind, that this applies to any global triggering, not just ajax events.

comment:7 Changed 15 years ago by flesler

Resolution: duplicate
Status: newclosed

#3107 improves this situation quite a bit.

Note: See TracTickets for help on using tickets.