gpt4 book ai didi

javascript - 为什么 DOM 操作需要这么长时间?

转载 作者:行者123 更新时间:2023-11-28 13:46:34 25 4
gpt4 key购买 nike

我过去读过,操作 DOM 是在 javascript 中可以做的最昂贵的事情之一。我也在 perfs 中看到了它的演示。为什么要这么长时间?

最佳答案

这种缓慢是由于文档重排造成的。来自 Google 开发者 Speeding up JavaScript: Working with the DOM guide

Working with the DOM can cause browser reflow, which is the browser's process of determining how things should be displayed. Directly manipulating the DOM, changing CSS styles of elements, and resizing the browser window can all trigger a reflow. Accessing an element's layout properties such as offsetHeight and offsetWidth can also trigger a reflow. Because each reflow takes time, the more we can minimise browser reflow, the faster our applications will be.

关于javascript - 为什么 DOM 操作需要这么长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13863730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com