开发者

jQuery selector optimisation : sizzle / pseudo / hidden

开发者 https://www.devze.com 2023-02-09 18:56 出处:网络
I used Visual Studio 2010 excellent javascript profiler to profile the javascript of a web page on Internet Explorer.

I used Visual Studio 2010 excellent javascript profiler to profile the javascript of a web page on Internet Explorer. (Analyze / Launch perf wizard / Instrumentation / JS application / profile js + url of page)

The perf report shows that jQuery's sizzle is the cause of the slowness (ie: some jquery selectors on my web page).

It shows the time spent is in Sizzle > filter > hidden > PSEUDO. I do not have any selector with :hidden, so i don't understand why it looses this much time in hidden.

I'm using jQuery 1.4.4 开发者_StackOverflow中文版I tried with jQuery 1.5 and it is the same.


As mentioned in the comment, :visible calls :hidden so if you're using that, it will show in the profiler.

Also note, that on the jQuery doc for the :hidden selector it mentions

Because :hidden is a jQuery extension and not part of the CSS specification, queries using :hidden cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :hidden to select elements, first select the elements using a pure CSS selector, then use .filter(":hidden").

0

精彩评论

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