Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes chaining with queue() and filter() in Jquery increase performance?
    primarykey
    data
    text
    <p>I'm cleaning up some Jquery code. I always read, chaining is good for performance. </p> <p><strong>Question:</strong><br> Does this also include chains with a lots of <strong>queue() and filter()</strong>?</p> <p>For example, I have <strong>unchained</strong>:</p> <pre><code>var self = this, co = el.jqmData("panel"), pop = $('div:jqmData(id="'+co+'")'), wrap = pop.closest('div:jqmData(wrapper="true")'); if ( pop.is(":visible") ) { if ( pop.hasClass('switchable') &amp;&amp; wrap.jqmData('switchable') ) { pop.css('display','none').addClass("switched-hide"); self.panelWidth( true ); } else { self.hideAllPanels("8"); } } else { if ( pop.hasClass('switchable') &amp;&amp; wrap.jqmData('switchable') ) { pop.css('display','block').removeClass("switched-hide"); self.panelWidth( true ); } else { self.hideAllPanels("8"); if ( pop.hasClass('ui-popover-center') ){ pop.css("left", (($(window).width() - pop.outerWidth()) / 2) + $(window).scrollLeft() + "px"); } pop.jqmData("fixed") == "top" ? pop.css( "top", $( window ).scrollTop() + "px" ) : pop.css( "bottom", wrap.outerHeight() - $( window ).scrollTop() - $.mobile.getScreenHeight() + "px" ); ...there's more } </code></pre> <p>Which I didn't like for the duplicate code in the first place. I'm now playing around with a chained version like so and am afraid I'm overdoing it:</p> <pre><code> wrap.filter(':jqmData(switchable="true")') .find( pop ) .filter('.switchable:visible') .css('display','none') .addClass("switched-hide") .end() .filter('.switchable:hidden') .css('display','block') .removeClass("switched-hide") .end() .queue(function(next){ self.panelWidth( true ) next(); }) .end() .end() // back to wrap .filter(':not(:jqmData(switchable="true")') .find( pop ) .queue(function(next){ self.hideAllPanels("8") next(); }) .filter('.ui-popover-center') .css("left", (($(window).width() - pop.outerWidth()) / 2) + $(window).scrollLeft() + "px") .end() .filter(':jqmData(fixed="top")') .css( "top", $( window ).scrollTop() + "px" ) .end() .filter(':jqmData(fixed="bottom")') .css( "bottom", wrap.outerHeight() - $( window ).scrollTop() - $.mobile.getScreenHeight() + "px" ) .end() ... </code></pre> <p><strong>Question</strong>:<br> Is there a point where chaining Jquery is turning negative for performance, especially if using queue() and filter() or should I just keep on going?</p> <p>Thanks for input!</p> <p>PS: Haven't tested the above. There are probably a few mistakes. I'm looking more for conceptual info.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload