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

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

问题描述

我正在摄取一个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响应非常大,并且只会在将数据添加到DB中时才会变得更大.

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天全站免登陆