From: Jack Mahoney Date: Wed, 12 Feb 2014 03:31:51 +0000 (+1100) Subject: Optimise tight loop on foundation.js X-Git-Tag: v5.2.0~61^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4426%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Optimise tight loop on foundation.js We should avoid jQuery selector repeats. Here I have cached the $('head') calls occurring on lines 17 and 18 --- diff --git a/js/foundation/foundation.js b/js/foundation/foundation.js index 666e18bf8..ad3385303 100644 --- a/js/foundation/foundation.js +++ b/js/foundation/foundation.js @@ -11,10 +11,11 @@ var header_helpers = function (class_array) { var i = class_array.length; + var head = $('head'); while (i--) { - if($('head').has('.' + class_array[i]).length === 0) { - $('head').append(''); + if(head.has('.' + class_array[i]).length === 0) { + head.append(''); } } };