我已经实现了无限滚动(即当滚动条到达 div 底部时加载记录)。它工作正常,但在页面上加载太多记录后,页面变得太重并导致渲染缓慢。实际上,我正在使用这种技术来替代 gridview,那么在这种情况下我如何管理繁重的 DOM?
- 将 DOM 元素减少到最少。
- 尽量减少包装纸的数量。
- Minimize the acces to the DOM elements, which includes ( yahoo suggestions ):
- 缓存对访问元素的引用
- “离线”更新节点,然后将它们添加到树中
- 避免使用 JavaScript 修复布局
- If there is any computation which can be reduced, like getting the number of rows ( don't calculate it everytime, just add the number of the new rows to the current ), cache it ( memoization wikipedia )
如果您对 DOM 元素集合有任何类型的迭代并且不使用 jQuery 进行迭代,请使用此(建议JavaScript 模式):
for (var iteration = 0, limit = lengthOfElements; iteration++; iteration < limit)
or
for (var i = myarray.length; i--; )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)