您如何决定在单页应用程序中向用户推送多少数据?

时间:2021-04-09 16:27:02

Say you have a Recipe Manager application that you're building with a Web Api project. Do you send the list of recipes along with their ingredient names in JSON? Or do you send the recipes, ingredient names, and ingredient details? What's the process in determining how big the initial payload should be for a SPA?

假设您有一个使用Web Api项目构建的Recipe Manager应用程序。您是否在JSON中发送食谱列表及其成分名称?或者您是否发送食谱,成分名称和成分详细信息?确定SPA的初始有效载荷有多大的过程是什么?

4 个解决方案

#1


12  

These are the determining factors in how much to send to the client in an initial page:

这些是在初始页面中向客户端发送多少的决定因素:

  1. Data that will be displayed for that first page
  2. 将为该第一页显示的数据

  3. Lookup list data for any drop downs on that page
  4. 查找该页面上任何下拉列表的数据

  5. Data that is required for and presentation rules (might not be displayed but is used)
  6. 所需数据和演示规则(可能未显示但已使用)

On a recipe page that would show a list of recipes, I would get the recipes and some key factors to display (like recipe name, the dish, and other key info) that can be displayed in a list. Enough for the user to make a determination on what to pick. Then when the user dives into a recipe, then go get that 1 recipe's details.

在显示食谱列表的食谱页面上,我会得到食谱和一些可以显示的关键因素(如食谱名称,菜肴和其他关键信息)。足以让用户确定要选择的内容。然后当用户潜入食谱时,去获取该食谱的详细信息。

The general rule is get what you user will almost certainly need up front. Then get other data as they request it.

一般规则是获得用户几乎肯定需要的东西。然后在他们请求时获取其他数据。

#2


6  

The process by which you determine how much data to send solely depends on the experience you want to provide your users - however it's as simple as this. If my experience demands that I readily display all of the recipes with a brief description and then allow them to drill into the recipe to get more information, then I'm only going to send enough information to produce the display and navigate further into the entity.

确定要发送多少数据的过程取决于您希望为用户提供的体验 - 但它就像这样简单。如果我的经验要求我很容易地用简短的描述显示所有的食谱然后让他们钻进食谱以获得更多信息,那么我只会发送足够的信息来生成显示并进一步导入实体。

If then after navigating into the recipe it requires that you display the ingredient names and measures then send down that and enough information to navigate further into any single ingredient.

如果在导航到配方后,它要求您显示配料名称和度量,然后发送该信息和足够的信息以进一步导入任何单一成分。

And as you can see it just goes on and on.

正如你所看到的那样,它一直在继续。

#3


4  

It depends if your application is just a simple HTTP API backing your web page, or your goal is something more akin to Platform As A Service. One driver for the adoption of SPA is that it makes the browser another client, just like an iOS or Android app,or a 3rd party.

这取决于您的应用程序是否只是支持您的网页的简单HTTP API,或者您的目标更类似于平台即服务。采用SPA的一个驱动因素是它使浏览器成为另一个客户端,就像iOS或Android应用程序或第三方一样。

If you want to support multiple clients, then it's likely that you want to design your APIs around the resources that you are trying to expose, such that you can use the uniform interface of GET/POST/PUT etc. against that resource. This will means it is much more likely that you are not coding in an client specific style and your API will be usable by a wide range of clients.

如果您想支持多个客户端,那么您可能希望围绕您尝试公开的资源设计API,以便您可以使用GET / POST / PUT等统一接口来对抗该资源。这意味着您更有可能不以客户特定的样式进行编码,并且您的API可供各种客户使用。

A resource is anything you would want to have its own URN.

资源是您希望拥有自己的URN的任何资源。

I would suggest that is likely that in this case you would want a Recipe Book resource which has links to individual Recipe resources, which probably contain all the information necessary for that Recipe. Ingredients would only be a separate resource if you had more depth on what an Ingredient contained and they had their own resource.

我建议在这种情况下,您可能需要一个食谱书资源,该资源包含指向各个食谱资源的链接,这些资源可能包含该食谱所需的所有信息。如果您对成分所含的内容有更深入的了解,并且他们拥有自己的资源,那么成分将只是一个单独的资源。

At Huddle we use a Documentation Driven Design approach. That is we write the documentation for our API up front so that we can understand how usable our API would be. You can measure API quality in WTFs. http://code.google.com/p/huddle-apis/

在Huddle,我们使用文档驱动设计方法。那就是我们预先为我们的API编写文档,以便我们了解API的可用性。您可以测量WTF中的API质量。 http://code.google.com/p/huddle-apis/

Now this logical division might not be optimal in terms of performance. Your dealing with a classic tradeoff (ultimately architecture is all about balancing design tradeoffs) here between usability of your API and the performance of your API. Usually, don't favour performance until you know that it is an issue, because you will pay a penalty in usability or maintainability for early optimization.

现在,这种逻辑划分在性能方面可能不是最佳的。您在API的可用性和API的性能之间处理经典的权衡(最终架构是关于平衡设计权衡)。通常,在您知道这是一个问题之前不要偏向性能,因为您将在可用性或可维护性方面为早期优化付出代价。

#4


0  

Another possibility is to implement the OData query support for WebAPI. http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api

另一种可能性是为WebAPI实现OData查询支持。 http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api

That way, your clients can perform their own queries to return only the data they need.

这样,您的客户端可以执行自己的查询,只返回所需的数据。

#1


12  

These are the determining factors in how much to send to the client in an initial page:

这些是在初始页面中向客户端发送多少的决定因素:

  1. Data that will be displayed for that first page
  2. 将为该第一页显示的数据

  3. Lookup list data for any drop downs on that page
  4. 查找该页面上任何下拉列表的数据

  5. Data that is required for and presentation rules (might not be displayed but is used)
  6. 所需数据和演示规则(可能未显示但已使用)

On a recipe page that would show a list of recipes, I would get the recipes and some key factors to display (like recipe name, the dish, and other key info) that can be displayed in a list. Enough for the user to make a determination on what to pick. Then when the user dives into a recipe, then go get that 1 recipe's details.

在显示食谱列表的食谱页面上,我会得到食谱和一些可以显示的关键因素(如食谱名称,菜肴和其他关键信息)。足以让用户确定要选择的内容。然后当用户潜入食谱时,去获取该食谱的详细信息。

The general rule is get what you user will almost certainly need up front. Then get other data as they request it.

一般规则是获得用户几乎肯定需要的东西。然后在他们请求时获取其他数据。

#2


6  

The process by which you determine how much data to send solely depends on the experience you want to provide your users - however it's as simple as this. If my experience demands that I readily display all of the recipes with a brief description and then allow them to drill into the recipe to get more information, then I'm only going to send enough information to produce the display and navigate further into the entity.

确定要发送多少数据的过程取决于您希望为用户提供的体验 - 但它就像这样简单。如果我的经验要求我很容易地用简短的描述显示所有的食谱然后让他们钻进食谱以获得更多信息,那么我只会发送足够的信息来生成显示并进一步导入实体。

If then after navigating into the recipe it requires that you display the ingredient names and measures then send down that and enough information to navigate further into any single ingredient.

如果在导航到配方后,它要求您显示配料名称和度量,然后发送该信息和足够的信息以进一步导入任何单一成分。

And as you can see it just goes on and on.

正如你所看到的那样,它一直在继续。

#3


4  

It depends if your application is just a simple HTTP API backing your web page, or your goal is something more akin to Platform As A Service. One driver for the adoption of SPA is that it makes the browser another client, just like an iOS or Android app,or a 3rd party.

这取决于您的应用程序是否只是支持您的网页的简单HTTP API,或者您的目标更类似于平台即服务。采用SPA的一个驱动因素是它使浏览器成为另一个客户端,就像iOS或Android应用程序或第三方一样。

If you want to support multiple clients, then it's likely that you want to design your APIs around the resources that you are trying to expose, such that you can use the uniform interface of GET/POST/PUT etc. against that resource. This will means it is much more likely that you are not coding in an client specific style and your API will be usable by a wide range of clients.

如果您想支持多个客户端,那么您可能希望围绕您尝试公开的资源设计API,以便您可以使用GET / POST / PUT等统一接口来对抗该资源。这意味着您更有可能不以客户特定的样式进行编码,并且您的API可供各种客户使用。

A resource is anything you would want to have its own URN.

资源是您希望拥有自己的URN的任何资源。

I would suggest that is likely that in this case you would want a Recipe Book resource which has links to individual Recipe resources, which probably contain all the information necessary for that Recipe. Ingredients would only be a separate resource if you had more depth on what an Ingredient contained and they had their own resource.

我建议在这种情况下,您可能需要一个食谱书资源,该资源包含指向各个食谱资源的链接,这些资源可能包含该食谱所需的所有信息。如果您对成分所含的内容有更深入的了解,并且他们拥有自己的资源,那么成分将只是一个单独的资源。

At Huddle we use a Documentation Driven Design approach. That is we write the documentation for our API up front so that we can understand how usable our API would be. You can measure API quality in WTFs. http://code.google.com/p/huddle-apis/

在Huddle,我们使用文档驱动设计方法。那就是我们预先为我们的API编写文档,以便我们了解API的可用性。您可以测量WTF中的API质量。 http://code.google.com/p/huddle-apis/

Now this logical division might not be optimal in terms of performance. Your dealing with a classic tradeoff (ultimately architecture is all about balancing design tradeoffs) here between usability of your API and the performance of your API. Usually, don't favour performance until you know that it is an issue, because you will pay a penalty in usability or maintainability for early optimization.

现在,这种逻辑划分在性能方面可能不是最佳的。您在API的可用性和API的性能之间处理经典的权衡(最终架构是关于平衡设计权衡)。通常,在您知道这是一个问题之前不要偏向性能,因为您将在可用性或可维护性方面为早期优化付出代价。

#4


0  

Another possibility is to implement the OData query support for WebAPI. http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api

另一种可能性是为WebAPI实现OData查询支持。 http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api

That way, your clients can perform their own queries to return only the data they need.

这样,您的客户端可以执行自己的查询,只返回所需的数据。