更好的性能,空元素或使用Javascript创建和销毁? [英] Better Performance, Empty Elements Or Create And Destroy With Javascript?

查看:87
本文介绍了更好的性能,空元素或使用Javascript创建和销毁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

性能会更好,页面上有许多隐藏元素,或者根据请求使用javascript创建并销毁它们。例如,当点击某个元素时,元素首先被创建并显示。当它关闭时,它会被销毁。那会比在页面中散布隐藏元素更好吗?

我会想象它部分取决于复杂程度元素是,并且部分地取决于你的表现。元素越复杂,创建它的代码越多,创建时间越长。因此,将元素隐藏在页面中可能会使其显示速度更快,但代价是更大的页面(并且要筛选更多的DOM),这可能会使整体速度降低一些。 p>

What would be better for performance, having many hidden elements on a page, or creating them and destroying them as they are needed with javascript upon request. For example, when something is clicked the element is first created and then shown. When it is closed it is then destroyed. Would that be better than having hidden elements scattered among the page?

解决方案

I'd imagine it depends in part on how complex the elements are, and in part on what you mean by "performance". The more complex the element, the more code has to run to create it, and the longer it'll take to create. Thus, hiding the element in the page would probably make it appear faster, but at the cost of a bigger page (and more DOM to sift through), which could slow things down a bit overall.

这篇关于更好的性能,空元素或使用Javascript创建和销毁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆