admin管理员组文章数量:1313925
Is there performance difference between:
<div>
<a> ... </a>
</div>
and:
<div>
<div>
<div>
<a> ... </a>
</div>
</div>
</div>
For Browsers I think it doesn't make sense but in my case I have list of 200 items that run on mobile.
So I pretty sensitive to performance.
Thanks,
Is there performance difference between:
<div>
<a> ... </a>
</div>
and:
<div>
<div>
<div>
<a> ... </a>
</div>
</div>
</div>
For Browsers I think it doesn't make sense but in my case I have list of 200 items that run on mobile.
So I pretty sensitive to performance.
Thanks,
Share Improve this question edited May 18, 2014 at 15:03 Sebas 21.5k9 gold badges59 silver badges109 bronze badges asked May 18, 2014 at 14:48 snaggssnaggs 5,71317 gold badges67 silver badges131 bronze badges 5- 1 any particular reason you need to have a deep dom? – Populus Commented May 18, 2014 at 14:50
- Yes, but it's negligible. CSS abd JavaScript are usually your major issues, not HTML. – Mohamad Commented May 18, 2014 at 14:51
-
@Populus generally ,yes, In angular I use directive defined as elements that must be wrapped by root DOM element. it demands me to add additional
div
– snaggs Commented May 18, 2014 at 14:51 - The answer to "does dom plexity affect performance?" is almost certainly yes, though to what extent depends on how --awful-- nested/none-semantic the html is. Since I have no references, no answer. – AD7six Commented May 18, 2014 at 14:52
- The easiest solution would be to do paging if you feel there are too many items... – Populus Commented May 18, 2014 at 15:00
3 Answers
Reset to default 9Yes, there are some potential performance issues. You should consider:
Download time. More HTML means a larger file, which takes longer to download.
DOM size. More elements means that the page uses more memory.
Rendering time. More elements means that the page is drawn more slowly.
What you would notice most is normally the download time. If the page is still reasonbly small you should be ok. If you are creating a lot of elements dynamically, then the other two could be noticable without the loading time being the problem.
As few as 200 items shouldn't be a big problem though.
In terms of mobile, the more nested the DOM tree is, more chances for performance issues.
When the DOM tree bees nested too much, traversing through the DOM tree will be PITA. It's always better to maintain flat DOM tree.
Even styling gets difficult when the DOM gets nested a lot.
In terms of page load speed, lesser the content more will be the page speed. If you are going to nest too many content in same page, it's going to affect the loading of page.
I think you should optimize that using section as below :
<section> </section> => for your content
But, why using 3 divs with no id and class ?
You should reduce your DOM like that :
<div> <a href="/yourlink" title="Your title" target="_blank" rel="Your title">Content</a> </div>
More you should reduce your DOM loading content in order to improve load , don't use three divs if you have no class and id on it :)
本文标签: javascriptIs there performance penalty for div tree depthStack Overflow
版权声明:本文标题:javascript - Is there performance penalty for div tree depth? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741960960a2407275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论