我怎样才能自动找出哪些 jQuery 选择器在我的网站上运行缓慢?有这个插件吗?

How can I automatically find out which jQuery selectors are slow on my site ? Is there a plugin for this?

我想在 jQuery 选择器运行缓慢时自动检测 (> some_millis) 我希望它在控制台记录有关行号的信息。

我的第一个想法是覆盖核心 jQuery 选择器代码以在其中插入这样的测试,但是是否有现有的插件来实现这一点,有人尝试过类似的东西吗?某些浏览器工具可以做到这一点(也许可以过滤分析器中的方法调用)吗?

请注意,我不想在每个选择器调用周围放置一些性能监控 js 代码!

快速 google 搜索结果:

  1. http://seesparkbox.com/foundry/jquery_selector_performance_testing
  2. https://learn.jquery.com/performance/optimize-selectors/

对 JS 分析器的引用已失效,但这里有一个更好的方法 Chrome:

https://developer.chrome.com/devtools/docs/cpu-profiling

Now open the Chrome DevTools, navigate to the Profiles panel, and verify "Collect JavaScript CPU Profile" is selected. Now, click the Start button or press Cmd + E start recording a JavaScript CPU profile.