JQuery global events and performance?

I was looking for a way to show a status indicator using jQuery and I found a solution in the jQuery cookbook, it showed this solution

(function($) {
    $(document).ready(function() {
       $('#ajaxStatus')
         .ajaxStart(function() {
            $(this).show();
        })
         .ajaxStop(function() {
            $(this).hide();
        });

        .....
  })(jQuery);

he warned

If you have performance problems in the application, this may be due to the fact that the cost of the distribution of events, if there is a significantly large number of elements. In this case, setting the global value to false can give you a performance improvement.

So, you should first use the above solution, and will it be a performance issue as my site and js code get bigger and bigger?

Should I avoid jQuery global events, just disable it, as the paragraph says?

, , , , ajax?

+3
1

, , , . jQuery : http://github.com/jquery/jquery/blob/master/src/event.js#L290

, :

if ( jQuery.event.global[ type ] ) {
  jQuery.each( jQuery.cache, function() {
    if ( this.events && this.events[type] ) {
      jQuery.event.trigger( event, data, this.handle.elem );
    }
  });
}

:

jQuery("*").add([window, document]).trigger(type, data);

, , , , , , , - , .


:

, , , js ?

, , , , , , , .

jQuery, , ?

, , jQuery .

, , , , ajax?

, :)

+9

Source: https://habr.com/ru/post/1752743/


All Articles