简体   繁体   English

如何使用 React.js 和 Node.js 仅将所需资源加载到客户端浏览器

[英]How can I load only required resources to client browser with React.js and Node.js

I am going to building a very large SPA based ERP SaaS with react.js at frontend which has a really complicated role and permission-based system .我将在前端使用 react.js 构建一个非常大的基于 SPA 的 ERP SaaS ,它具有非常复杂的角色和基于权限的系统 I have done some analysis of my application so I realized that I must make a proper architecture of my application so that I shouldn't regret and worry about my application and it's scalability in the future.我已经对我的应用程序进行了一些分析,因此我意识到我必须为我的应用程序建立一个适当的架构,这样我就不应该后悔和担心我的应用程序及其未来的可扩展性。 Mainly I was worried about role and base management.主要是我担心角色和基地管理。 Where I need to switch between different components at first load.我需要在第一次加载时在不同组件之间切换。

Backend I am working with on this project: Php and node.js我正在处理这个项目的后端:Php 和 node.js

My Exact Problem : I have about 500+ permissions with 100+ roles in my system.我的确切问题:我的系统中有大约 500 多个权限和 100 多个角色。 Some roles get only 1 to 10 permissions.某些角色仅获得 1 到 10 个权限。 This results in switching and showing the only component of that permission in the client browser at the frontend.这导致在前端的客户端浏览器中切换并显示该权限的唯一组件。 My main problem is Why should I load unwanted components in the client browser of which users don't have permission to access?我的主要问题是为什么我应该在用户无权访问的客户端浏览器中加载不需要的组件?

Problem Example: Admin has given only 3 permissions to Mr.John in their system.问题示例:管理员在他们的系统中只向 Mr.John 授予了 3 个权限。 Where system contains total of 100 permissions.其中系统总共包含 100 个权限。 Each permission results in switching and viewing 100 parent components.每个权限都会导致切换和查看 100 个父组件。 If Mr.John has only 3 permissions which should switch only 3 parent components so why other components are sent to the client browser?如果 Mr.John 只有 3 个权限,应该只切换 3 个父组件,那么为什么要将其他组件发送到客户端浏览器?

What did I want to do?我想做什么?

After authentication, I want to verify the permission and role of that user at the backend and send only the required resources to the client.身份验证后,我想在后端验证该用户的权限和角色,并只向客户端发送所需的资源。 So that My application size depends upon the role and permission that a particular user has.所以我的应用程序大小取决于特定用户的角色和权限。

To solve this problem what I thought (Not Sure) :为了解决这个问题我的想法(不确定)

Before this project I have a similar project at PHP without using any complicated frontend library.在这个项目之前,我在 PHP 有一个类似的项目,没有使用任何复杂的前端库。 It was really easy during the development phase.在开发阶段真的很容易。 I have worked with React and Vue.我曾使用过 React 和 Vue。 But I have never used Server-side-rendering.但我从未使用过服务器端渲染。 I thought the concept of SSR could help me so I went to tons of sources and learned about SSR.我认为 SSR 的概念可以帮助我,所以我查阅了大量资源并了解了 SSR。 (Still, I am not sure that the concept of SSR can help me. ) (不过,我不确定 SSR 的概念是否可以帮助我。)

Please Help me to make the proper decision?请帮助我做出正确的决定?

What I understand about your problem is How can browser load exact files based on role and permission instead of all files.我对您的问题的理解是浏览器如何根据角色和权限而不是所有文件加载确切的文件。

Code-splitting is what you want exactly.代码拆分正是您想要的。 This is not just React but for all front-end framework(or library) by using webpack这不仅适用于 React,而且适用于所有前端框架(或库),使用webpack

Read official articles阅读官方文章

Maybe entry point of a bundle(webpack) must be simple.也许包(webpack)的entry point必须很简单。 After getting a role and permission, the browser has to load components you want.获得角色和权限后,浏览器必须加载您想要的组件。 Also, maybe react-router helps you.此外,也许react-router可以帮助您。 Or if you consider server-sider-rendering, next.js is for you或者,如果您考虑服务器端渲染, next.js适合您

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

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