哪一个更好:在服务器上或在客户端JS渲染HTML? [英] Which is better: HTML rendering on server or on client in JS?

查看:107
本文介绍了哪一个更好:在服务器上或在客户端JS渲染HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个最佳实践/性能问题。我创建一个ASP.NET MVC 2的项目,我有要么在装载时或用户交互动态访问页面的几个部分。

I have a best practices/performance question. I am creating an ASP.NET MVC 2 project, and I have several parts of the page that are accessed dynamically either at load time or on user interaction.

我的问题是:是它更好地在HTML渲染服务器上的部分,然后就取代HTML的部分或者是它最好只检索信息的JSON对象,然后用JS来创建并插入HTML?

My question is this: is it better to have the sections rendered in HTML on the server and then just replace the sections of HTML or is it better to just retrieve the information as JSON objects and then use JS to create and insert the HTML?

应当指出的是关注的对象是在本质上非常简单。一个例子将是一个消息对象具有一个ID字段,以场,从字段,主题字段和主体字段是所有字符串。

It should be noted that the objects of concerns are very simple in nature. An example would be a 'message' object that has an ID field, a to field, a from field, a subject field and a body field that are all strings.

是否有一些严重的优势和劣势,以两种方法?或者这是preference对如何构建你的应用程序的案例?

Are there some serious advantages or disadvantages to either approach? Or is this a case of preference to how to construct your application?

推荐答案

我不认为任何更好;这将取决于您的需求。现在的问题是边缘无法回答。您是否使用客户端进行进一步的计算或处理的数据或者你只是plopping出来的东西要显示?

I don't think either are better; it's going to depend on your requirements. The question is borderline unanswerable. Are you using the data on the client for further computation or manipulation or are you just plopping something out to be displayed?

在您输出的文本数据,但它恰好是更容易更直接比它的数据结构转换为HTML重新present数据结构JSON和更容易直接显示HTML比JSON两种情况。

In both cases you're outputting textual data, though it happens to be easier to represent data structures as JSON more directly than it is to convert data structures to HTML and it's easier to directly display HTML than JSON.

这篇关于哪一个更好:在服务器上或在客户端JS渲染HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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