📜 ⬆️ ⬇️

Caching selectors for jQuery. Plugin

A simple jQuery plugin that allows you to cache the work of selectors.
On a tip from tenshi in cam to habrahabr.ru/blogs/javascript/63119

( function ($) {

var selectorCache = [];

$.cache = {

get : function (selector) {
return selectorCache[selector] || (selectorCache[selector] = $(selector));
},

clear: function (selector) {
selector == null ? selectorCache = [] : selectorCache[selector] = null ;
}
}

})(jQuery);

* This source code was highlighted with Source Code Highlighter .

Use something like this:
// Before
$( '#some .css .selector' ).some().action();

// After
$.cache.get( '#some .css .selector' ).some().action();


* This source code was highlighted with Source Code Highlighter .

')

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


All Articles