开发者

does jQuery use indexes into the DOM to speed performance?

I was wondering whether jQuery builds indexes into the DOM to speed up selector performance, or does it just loop/recurse round the DOM whenever you're selecting elements?

The reasoning is that I'm trying to do some manipulation t开发者_如何学Chat is quite performance sensitive and would be reasonably easy in plain old js/DOM and a bit more convoluted using jQuery selectors. I would kick myself if I did it the js way but found out jQuery would have been faster to execute


jQuery does not perform any indexing as far as I know. It always parses the specified selector and traverses the DOM. Of course there are ways to speed up a selector - specifying a tag name or id helps a lot. You can check this presentation for some tips.

If I were you I would make two small prototype of my application using jQuery and vanilla DOM traversing. Then after benchmarking I would decide if jQuery performance meets my requirements.


There is no jQuery code that you can't compete with. It uses the same DOM API. Most of the time you can achive far greater performance than jQuery. If it's even easier for you, definetely go for it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜