静态HTML呈现和动态DOM元素呈现之间的性能差异 [英] Performance difference between static HTML rendering and dynamic DOM element rendering

查看:118
本文介绍了静态HTML呈现和动态DOM元素呈现之间的性能差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建在线调查应用程序。我正在翻几页的问题。我将使用Ajax方法,在用户通过调查进行翻页时,容器div会随着下一个问题而更新。问题将存储在服务器上。我应该从服务器返回完整的HTML片段,并直接设置div html,还是应该返回表示问题的JSON对象以及客户端上的一些动态DOM操作以将HTML呈现到div中?我对动态方法更感兴趣,但是想知道在iPad上运行时是否会出现性能问题(以前在iPad上看到的jquery性能很差)。

非常感谢。

解决方案

除非你做了一件奇怪的事情,否则你永远不会注意到两者之间的性能差异。然而,你可能会注意到带宽的差异,因为生成的HTML肯定会比任何传递的结构大得多。无论如何,最大的决定因素应该是是否要在服务器或客户端上生成结构。我的投票总是在客户端:)


I am building an online survey app. I am rendering questions over several pages. I am going to use an Ajax approach, where a container div is updated with the next question as the user pages through the survey. The questions will be stored on the server. Should I return a fully formed HTML fragment from the server, and set the div html directly, or should I return a JSON object representing the questions and some dynamic DOM manipulation on the client to render the HTML into the div? I am keener on the dynamic approach, but wondered if there might be a performance issue when running on an iPad (having seen poor jquery performance on an iPad in the past).

Thanks very much.

解决方案

Unless you're doing something absurdly odd you'll never notice any performance difference between the two. You may, however, sometimes notice a difference in bandwidth since the generated HTML will certainly be much larger than any structure passed down.

Either way, the biggest deciding factor should be whether you want to generate the structure on the server or client. My vote is always on the client :)

这篇关于静态HTML呈现和动态DOM元素呈现之间的性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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