Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在预览内容很多且包含很多代码片段的文档时,加载速度非常慢,有时会让整个页面卡死。
浏览器的性能分析报告如下:
布局耗时 36 秒,布局排班中的色块是分成很多段的,这说明触发了很多次布局。
点击跳转源码界面,e.innerText 这一行代码耗时最高:
由此可看出每次
e.before(divElement)
后获取元素的 innerText 都会重新布局一次。解决方法是改成先批量获取 innerText,然后再批量插入新元素。优化后的效果如下,耗时大幅减少。