我有一个 news aggregator page有多个过滤器。公司过滤器有大量的公司。在 Chrome 中单击 + 按钮展开列表并查看公司列表时,需要 6-8 秒才能看到整个列表。在 Firefox 中,该列表几乎立即可见。有人可以帮我调查可能导致浏览器加载时间差异的原因吗?
最佳答案
您需要提高 DOM 节点查找性能:
$newsFilterRow.on('click', '.js-filter-more', function(event) {
var $this = $(this)
var $items = $this.closest($newsFilterRow).find($newsFilterItem).filter(':hidden');
var tmp = $items.splice(0, 56);
$(tmp).addClass(newsFilterItemVisibleClass).css('display', 'inline-block');
if ($items.length === 0) {
$this.remove();
}
});
您正在使用 .find() 和 .filter()
我建议更改这些过滤器以提高 中的性能 Chrome .
http://www.steveworkman.com/html5-2/javascript/2011/improving-javascript-xml-node-finding-performance-by-2000/
关于google-chrome - 什么会导致 Chrome 和 Firefox 之间的过滤器加载速度不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29349866/