减少 dom 元素的方法
1. 使用伪元素, 阴影实现的内容尽量不要使用 dom 元素, 例如清除浮动, 样式实现等
2. 按需加载, 减少不必要的元素
3. 结构合理, 语义化标签
大量的 dom 元素时优化:
1. 缓存 dom 对象
- let root = document.querySelector('a');
- let childList = root.child;
- for(let i=0;i<childList.length;i++){
- // 执行操作
- }
2. 文档片段
let fragement = document.createDocumentFragment();
3. 用 innerhtml 替代高频的 appendChild
4. 虚拟 dom
来源: http://www.bubuko.com/infodetail-3655139.html