简体   繁体   中英

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. 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.

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. 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. From my experience, it hasn't caused any performance issues so far with 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.

Also what error are you getting?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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