All,
I had a few question regarding DOM caching and jquery and how it
effects overall performance.
Assumptions (based on my knowledge):
1) jquery does not cache its queries
2) In general, walking the DOM to find matching elements, classes and
attributes does have a performance hit. I understand that their are
speed advantages of using XPath over css selectors, etc. I will assume
that jquery (since it is so tight) does the optimal thing when walking
the DOM.
3)The user of jquery can speed up the DOM walk performance by
providing more information [ie $('div.class') vs. $('.class') ]
In the past, I have used a hash (ie the DOM cache) to store DOM
elements after they are fetched one time. More often than not, I do
these inital DOM walks once the DOM has been loaded (the
$(document).ready ). From that point forward, I can use the hash to
retrieve the actual DOM objects and pass them to jquery. This avoids
DOM walks on every jquery usage.
Questions:
1) Do browsers implement a DOM cache for you?
2) Has any thought been given to a plugin or a modification to jquery
to cache the DOM objects resulting from queries for laster use?
An high level implementation would be:
- The hash key could be the query (ie "div.class" or whatever jquery
expression you pass to $())
- The value would be the DOM object.
When a query is made, the cache would be checked first, if it is
there, it is used. If it is not there, it could be retrieved (DOM
walk) and then also stored in the cache.
- You would have to allow for an overide of the cache in case you
added to the DOM since last query.
Please let me know your thoughts and feedback. In addition, don't be
afraid to tell me if I am completely off base!!
Thanks,
Jeff
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/