前端与后端处理 [英] Front End vs Back-End processing

查看:30
本文介绍了前端与后端处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在摄取一个代码库,它是一个 React-NodeJS 堆栈.我试图掌握的概念之一是关于后端 API 及其处理客户端的方式.

I'm ingesting a codebase that is a React-NodeJS stack. One of the concepts that I am trying to grasp is regarding the back-end API and how its handled client side.

代码库本质上是通过 API 调用从 MongoDB 转储整个集合,然后使用 React 进行大量解析和客户端逻辑以呈现自定义视图.这里的 HTTP 响应非常大,并且只会随着数据添加到数据库而变大.

The codebase is essentially dumping an entire collection from MongoDB with an API call, and then doing a good amount of parsing and client side logic with React in order to render custom views. The HTTP responses here are pretty large, and will only get larger as data is added to the DB.

与在 NodeJS 中创建多个端点并利用 Mongoose 之类的东西将过滤后的数据返回给客户端相比,这种方法有什么优点/缺点,从而使渲染更容易,响应更小.

Is there any advantage/disadvantage to this approach, as opposed to creating multiple endpoints in NodeJS, and utilizing something like Mongoose to return filtered data to the client, making rendering easy and responses smaller.

需要考虑的因素可能是资源消耗、如果在云中将如何计费、SPA 的影响等.

Things to take into consideration could be resource consumption, how this would be billed if in the cloud, the impact of SPA's, etc.

希望我在这结束时能更清楚吗?

Hopefully i get some more clarity at the end of this?

推荐答案

客户端处理是最好的,因为如您所知,我们的服务器端资源是免费的并且可以轻松处理请求.处理会导致客户端开销并使他们的浏览体验不太可接受,数据安全可能会受到影响,或者网络可能会不堪重负并消耗带宽.服务器端处理数据会增加每个客户端的服务器负载.

Client-side processing is best because as you know our server-side resources are free and can easily handle requests.but Sending large amounts of data to the client for processing will incur client overhead and make their browsing experience less acceptable, data security may be compromised, or the network may be overwhelmed and bandwidth consumed. Processing data server side will increase your server load per client.

所以为了避免这些问题,最好先把这些冲突中的一些交给处理的数据库端(有过滤和特殊条件),然后用命令和编码过滤服务器端处理的安全数据不发送客户端.

So to avoid these issues, it is best to first hand over some of these conflicts to the side of the database handled (with filtering and special conditions) and then filter the security data processed in server side with command and coding that Do not send clients.

但是让我们在客户端机器上进行繁重的处理.当然,SPA 还有其他好处.

But let's do the heavy processing on the client machine. SPA has other benefits, of course.

所以我主要做服务器端处理 - 除非它真的是基本的东西,比如简单的排序等.

So I mostly do server-side processing - unless it's really basic stuff like simple sorting etc etc.

另外,不要假设启用了 JavaScript.您必须优雅地回退,这将需要服务器以任何方式进行处理.

Also, don't assume JavaScript is enabled. You have to fall back gracefully and that would require the server to do the processing anyhow.

这个链接告诉你服务器端和客户端编程的区别

这篇关于前端与后端处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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