Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: $.cache(label,selector) #18

Closed
say2joe opened this issue Feb 15, 2013 · 6 comments
Closed

Feature: $.cache(label,selector) #18

say2joe opened this issue Feb 15, 2013 · 6 comments

Comments

@say2joe
Copy link

say2joe commented Feb 15, 2013

I will be submitting a pull request for my branch, "feature-cache". This is my first contribution to the code base of jQuery, so please be patient with me. I have tried to read all the documentation and guidelines I could find, but I may have missed something.

I would like the jQuery Team to consider adding $.cache to the jQuery API to encourage reducing the number of (repeated) DOM lookups commonly found in web applications these days -- especially with the size of JavaScript code bases increasing with larger web applications. I have written all the necessary code and placed (IMHO) where it seemed to fit best -- manipulation.js. I have successfully built jQuery and tested it. The amount of code required for this functionality leaves an extremely small footprint -- and does NOT effect other piece of code in jQuery.

Here is my implementation (reference manipulation.js):

[5320]: cache = {} // this will be used to store the user-based jquery (DOM) objects.

[5855]: cache() // this method extends jquery so that a user may create cached DOM objects (ex. future or repetitive, event-based manipulation) using the following syntax:
$.cache("aLabelForSomeDomCollection","jquerySizzleSelector"); (ex. $.cache("animImages","img.animated");)
The user can then later retrieve that (jQuery-wrapped) DOM element or collection using: $.cache("animImages"); without any internal DOM traversal... just an object reference.
$.cache("animImages").update(); is a chainable method which updates (adds/removes) based on the current state of the DOM.
Note: Since the selector property has been deprecated/removed, I'm adding it back for cached elements here (for update()).

[5865]: updateElements // this function is assigned to the update property of the cached object. This functionality may or may not prove useful in other use cases.

In summation, I've been writing JavaScript for a couple years now where I almost always cache and DOM objects that will be re-used. Not only have I seen the importance in my own code, but I've seen a growing number of web applications getting bloated with "divitus" and repeated selector lookups (even among more experienced developers I see this all too often). If jQuery had a caching mechanism introduced and promoted (especially since this code has an extremely small footprint), I believe people would use this functionality to at least speed up some web applications. I also feel that this feature fits very nicely with the fundamental principles of the JavaScript library we've all come to love!

Please provide any suggestions or thoughts. I would very much like to see if there's support for this much needed functionality in web applications, regardless of its exclusion or inclusion in jQuery.

@rwaldron
Copy link
Member

jQuery.cache is an existing legacy property that stored node data. This isn't the place for jQuery feature suggestions.

http://bugs.jquery.com/

@say2joe
Copy link
Author

say2joe commented Feb 15, 2013

The documentation clearly states that an issue should be created (though I forget exactly where). Thank you for the link -- I do see a comment about suggesting a new feature using the bug tracker. I wasn't thinking a bug tracker would be used for new feature requests, sorry.

@ajpiano
Copy link
Member

ajpiano commented Feb 15, 2013

RYI, @say2joe, this repository (jquery/jquery.com) is the actual content of the jquery.com website, so it is essentially unrelated to (beyond the obvious connection that it the website for) jQuery core :)

@say2joe
Copy link
Author

say2joe commented Feb 15, 2013

Thanks for the clarification... I'll get it right eventually.

On Fri, Feb 15, 2013 at 12:21 PM, adam j. sontag
notifications@github.comwrote:

RYI, @say2joe https://github.com/say2joe, this repository (jquery/
jquery.com) is the actual content of the jquery.com website, so it is
essentially unrelated to (beyond the obvious connection that it the website
for) jQuery core :)


Reply to this email directly or view it on GitHubhttps://github.com//issues/18#issuecomment-13626112.

Joe Johnson
657-464-HTML

@say2joe
Copy link
Author

say2joe commented Feb 15, 2013

Since this ticket is closed, and I had submitted my pull request to the
correct repo, I suppose I need do nothing more? I don't know how/why I
opened this ticket in jquery.com though. Sorry for any confusion.

On Fri, Feb 15, 2013 at 12:37 PM, Joe Johnson say2joe@gmail.com wrote:

Thanks for the clarification... I'll get it right eventually.

On Fri, Feb 15, 2013 at 12:21 PM, adam j. sontag <notifications@github.com

wrote:

RYI, @say2joe https://github.com/say2joe, this repository (jquery/
jquery.com) is the actual content of the jquery.com website, so it is
essentially unrelated to (beyond the obvious connection that it the website
for) jQuery core :)


Reply to this email directly or view it on GitHubhttps://github.com//issues/18#issuecomment-13626112.

Joe Johnson
657-464-HTML

Joe Johnson
657-464-HTML

@say2joe
Copy link
Author

say2joe commented Feb 15, 2013

I have opened the following bug (feature request): http://bugs.jquery.com/ticket/13460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants