简体   繁体   English

从前端设置虚拟个人资料图片是一个好习惯吗?

[英]Is setting the dummy profile pic from front-end a good practice?

I am working on a React app to show some profile information which you can also set a profile picture to a person.我正在开发一个 React 应用程序来显示一些个人资料信息,您还可以将个人资料图片设置为一个人。 I have recognized that the dummy profile image is set through the React App and until a person doesn't change it with a real one (ie saves a real profile pic to the database), the get request to fetch profile picture of that person returns not found.我已经认识到虚拟个人资料图片是通过 React App 设置的,直到有人没有用真实的图片更改它(即,将真实的个人资料图片保存到数据库中),获取该人个人资料图片的 get 请求返回未找到。

I find this a bit unusual.我觉得这有点不寻常。 All the projects I have worked with until now, set the dummy profile pic from the back-end when the person profile is created.到目前为止,我使用过的所有项目,在创建人员个人资料时从后端设置虚拟个人资料图片。

I am wondering if setting the dummy profile pic from front-end and getting not found responses from back-end until it is updated, has a significant effect on the overall health and stability of the app in the future.我想知道从前端设置虚拟配置文件图片并在更新之前从后端没有找到响应,是否会对应用程序的整体健康和稳定性在未来产生重大影响。 Can this be an acceptable approach?这是一种可以接受的方法吗? I am hesitating to complain about these get request errors since changing this will require a lot of back-end change I presume, which I don't have a profound knowledge about.我在犹豫要不要抱怨这些 get 请求错误,因为我认为更改这将需要进行大量后端更改,而我对此没有深入了解。 I don't want to put my nose into something that I am not quite certain too early.我不想过早地将我的鼻子放在我不太确定的事情上。 For now, it just annoys me to see errors on the console.现在,在控制台上看到错误让我很恼火。

I would like to learn if it is okay and if not, why?我想知道它是否可以,如果不行,为什么? Thanks.谢谢。

I don't think it's a bad approach, you can set the image from React as default, for me what I usually do is set the image from the backend, where there is an image served as default, or use logic to make a default image URL from gravatar using the email provided by the user.我不认为这是一个不好的方法,您可以将 React 中的图像设置为默认值,对我来说我通常做的是从后端设置图像,其中有一个图像作为默认值,或者使用逻辑来设置默认值使用用户提供的电子邮件从 gravatar 获取图像 URL。 From my experience, it hasn't caused any performance issues so far with react.根据我的经验,到目前为止,它没有对 react 造成任何性能问题。

For your case, if you don't want an unnecessary get request, and do a conditional rendering on the response of the request, you are fine to stick with the backend pre-fetch approach, where the default is already set when the user is registering and you serve it for your user profile call, it doesn't improve or decrease the performance of React, maybe if you have default image loaded in react app to be served, it may cause a delay, but that is not something to be taken into account unless its a large file.对于您的情况,如果您不想要不必要的 get 请求,并且对请求的响应进行条件渲染,则可以坚持使用后端预取方法,其中默认值已在用户访问时设置注册并为您的用户配置文件调用提供它,它不会提高或降低 React 的性能,也许如果您在 React 应用程序中加载了默认图像来提供服务,它可能会导致延迟,但这不是什么除非它是一个大文件,否则考虑在内。

Also what error are you getting?还有你得到什么错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM