且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在HTML中读取和替换文本会导致高CPU负载

更新时间:2023-02-23 14:31:34

正如@criz已经提到的,在循环中构建DOM是一种非常糟糕的做法。创建documentFragment并将其附加到DOM会好得多。请查看 https://developer.mozilla.org/ en-US / docs / Web / API / Document / createDocumentFragment 有一个例子。

As @criz already mentioned, building DOM in a loop is a very bad practice. It's much better to create documentFragment and attach it to the DOM. Take a look at the https://developer.mozilla.org/en-US/docs/Web/API/Document/createDocumentFragment There is an example.