I am using Google Analytic’s event tagging on a somewhat complicated code base. Instead of going through every file and finding where all of the necessary events are, I was thinking of creating new events using jQuery’s on method to delegate them. Should I be concerned about any potential performance issues by going along this route?
I am using Google Analytic’s event tagging on a somewhat complicated code base. Instead
Share
In a general note (I’m assuming because I’m just going with what you’ve shared), you shouldn’t be worried at all about performance when using delegates over binds. There are even arguments that delegate is better than bind on a level playing field, but I won’t go into details about that.
The most prominent performance pitfall you’ll find with delegates, though, is that by the nature of how they work, your events will have to bubble up to the delegated element before the actual event fires.
Now, if your code is complicated enough (as you seem to suggest), and if your DOM tree is deep enough (which I’m assuming since you’re considering using a delegate as a catch-all), your event will have to bubble up quite a good distance before the event fires.
Is the trigger delay significant enough for you to be worried about? Will it affect the asynchronous ordering of other events in your code (if that even matters)? You know your code, so you can tell it best.