惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
I
Intezer
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
小众软件
小众软件
T
Threatpost
B
Blog
美团技术团队
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyberwarzone
Cyberwarzone
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog
T
Tenable Blog
A
Arctic Wolf
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 叶小钗
L
Lohrmann on Cybersecurity
博客园 - 三生石上(FineUI控件)
L
LINUX DO - 热门话题
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
S
Security Affairs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
N
News and Events Feed by Topic
Cloudbric
Cloudbric
WordPress大学
WordPress大学
量子位
W
WeLiveSecurity
H
Hacker News: Front Page
Project Zero
Project Zero
S
Security @ Cisco Blogs
Security Latest
Security Latest
Hugging Face - Blog
Hugging Face - Blog
Forbes - Security
Forbes - Security
C
Cybersecurity and Infrastructure Security Agency CISA
人人都是产品经理
人人都是产品经理
U
Unit 42
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog

博客园 - focus

IE浏览器自定义地址协议 -- 通过B/S程序中打开C/S程序 Html编辑器 -- TinyMCE HTML编辑器 -- HtmlArea 用 BindingSource 绑定窗体中控件不失去焦点无法更新数据源的问题 - focus asp.net 服务器控件防止重复提交表单 - focus - 博客园 html 元素的 onpropertychange 事件 c# 操作 Excel : 给单元格增加下拉选项值 很黄的日期格式化。。。 - focus - 博客园 Asp.net 导出 .html,.txt 等格式的文件 ActiveReports 打印条码无法设置纸张大小? ActiveReports 代码控制报表连续打印 《JavaScript高级程序设计》读书笔记之一:几个与原始类型等价的引用类型的常用方法和属性 js:delete 操作符 js:for...in 语句(JavaScript For...In Statement) js:字符串类型快速转化成数字类型和数字类型快速转化为字符串类型 html 的 image button 自动提交 form Internet Explorer Developer Toolbar IE 最大化和最小化 js trim
动态创建大量 html dom 元素时提升性能 - focus
focus · 2008-02-27 · via 博客园 - focus

考虑以下两种做法:
方法1

<html>
    <head>
        <script>
        function createElements()
        {
            var t1 = new Date();
            for(var i = 0; i < 10000; i++)
            {
                var oP = document.createElement("p");
                oP.innerText 
= "hello world";
                document.all(
"div1").appendChild(oP);
            }
            var t2 = new Date();
            document.all("div2").innerText = "time span is:" + (t2 
- t1) + "ms";
        }
        </script>
    </head>
    <body onload="createElements()">
        <div id="div1" />
        <div id="div2" />
    </body>
</html>

输出结果:

time span is:6718ms

方法2

<html>
    <head>
        <script>
        function createElements()
        {
            var t1 = new Date();
            var oFragment = document.createDocumentFragment();
            for(var i = 0; i < 10000; i++)
            {
                var oP = document.createElement("p");
                oP.innerText 
= "hello world";
                oFragment.appendChild(oP);
            
}
            document.all("div1").appendChild(oFragment);
            var t2 = new Date();
            document.all("div2").innerText = "time span is:" + (t2 
- t1) + "ms";
        }
        </script>
    </head>
    <body onload="createElements()">
        <div id="div1" />
        <div id="div2" />
    </body>
</html>

输出结果:

time span is:1344ms

将新创建的元素临时 append 到一个 document fragment 对象上,全部创建完成之后再将此 document fragment 对象 apped 到 document 上,这样的话只是在 append document fragment 的时候刷新一次 dom,而不使用 document  fragment 对象在每次 append 的时候都会刷新 dom。因此方法二比方法一的性能得到了显著的提升!