WO2022135178A1 - 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 - Google Patents
微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 Download PDFInfo
- Publication number
- WO2022135178A1 WO2022135178A1 PCT/CN2021/137072 CN2021137072W WO2022135178A1 WO 2022135178 A1 WO2022135178 A1 WO 2022135178A1 CN 2021137072 W CN2021137072 W CN 2021137072W WO 2022135178 A1 WO2022135178 A1 WO 2022135178A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- application
- sub
- micro
- resource
- routing
- Prior art date
Links
- 238000011068 loading method Methods 0.000 title claims abstract description 117
- 238000004590 computer program Methods 0.000 title claims abstract description 18
- 230000006870 function Effects 0.000 claims description 49
- 244000035744 Hura crepitans Species 0.000 claims description 48
- 238000000034 method Methods 0.000 claims description 47
- 238000004891 communication Methods 0.000 claims description 36
- 230000005540 biological transmission Effects 0.000 claims description 24
- 230000007246 mechanism Effects 0.000 claims description 20
- 230000015654 memory Effects 0.000 claims description 19
- 238000013515 script Methods 0.000 claims description 14
- 230000008569 process Effects 0.000 claims description 9
- 238000012544 monitoring process Methods 0.000 claims description 8
- 238000013523 data management Methods 0.000 claims description 6
- 238000009877 rendering Methods 0.000 claims description 5
- 238000010586 diagram Methods 0.000 description 12
- 230000003068 static effect Effects 0.000 description 12
- 238000002955 isolation Methods 0.000 description 9
- 238000011161 development Methods 0.000 description 8
- 238000004806 packaging method and process Methods 0.000 description 6
- 208000028257 Joubert syndrome with oculorenal defect Diseases 0.000 description 5
- 238000011084 recovery Methods 0.000 description 5
- 230000004913 activation Effects 0.000 description 4
- 238000005516 engineering process Methods 0.000 description 4
- 230000003993 interaction Effects 0.000 description 4
- 238000012546 transfer Methods 0.000 description 4
- 230000008859 change Effects 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 238000012384 transportation and delivery Methods 0.000 description 3
- 238000013475 authorization Methods 0.000 description 2
- 238000013461 design Methods 0.000 description 2
- 238000007726 management method Methods 0.000 description 2
- 230000004044 response Effects 0.000 description 2
- VYZAMTAEIAYCRO-UHFFFAOYSA-N Chromium Chemical compound [Cr] VYZAMTAEIAYCRO-UHFFFAOYSA-N 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000000903 blocking effect Effects 0.000 description 1
- 230000006378 damage Effects 0.000 description 1
- 238000005538 encapsulation Methods 0.000 description 1
- 230000005294 ferromagnetic effect Effects 0.000 description 1
- 230000008014 freezing Effects 0.000 description 1
- 238000007710 freezing Methods 0.000 description 1
- 230000008676 import Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000005291 magnetic effect Effects 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
- 239000010979 ruby Substances 0.000 description 1
- 229910001750 ruby Inorganic materials 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/28—Databases characterised by their database models, e.g. relational or object models
- G06F16/284—Relational databases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/955—Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/955—Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
- G06F16/9566—URL specific, e.g. using aliases, detecting broken or misspelled links
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/451—Execution arrangements for user interfaces
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45504—Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
- G06F9/45529—Embedded in an application, e.g. JavaScript in a Web browser
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/505—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/541—Interprogram communication via adapters, e.g. between incompatible applications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/542—Event management; Broadcasting; Multicasting; Notifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/545—Gui
Definitions
- the embodiments of the present application relate to the field of Internet technologies, and relate to, but are not limited to, a micro front-end system, a sub-application loading method, an electronic device, a computer program product, and a computer-readable storage medium.
- micro-frontends came into being.
- the micro front-end draws on the concept of back-end micro-services, and splits a huge front-end project into small projects. These small projects are fully capable of independent development and operation. The whole system is coordinated by these small projects to realize the display and interaction of all pages.
- the micro-front-end framework routing service of related technologies uses Nginx service forwarding, which is inefficient.
- the central routing depends on the stability of the Nginx service, and the disaster recovery solution is complex. high.
- the embodiments of the present application provide a micro-front-end system, a sub-application loading method, an electronic device, a computer program product, and a computer-readable storage medium, which can improve capacity expansion and disaster tolerance through a node service that can maintain and operate independently, and provide Ability to run sub-applications under multiple frameworks.
- micro front-end system including:
- the routing registration service is a Node back-end service that maintains and operates independently, and is configured to provide the routing information of the sub-application, the loading method of the sub-application and the deployment information of the sub-application for the micro-front-end running framework of the main application;
- the command line tool is configured to provide a new sub-application function, an access sub-application function, and a service registration function through the command line;
- the micro-frontend running framework is a framework running on the main application, configured to load and run the sub-applications based on the acquired network request, and provide the sub-application running capability under multiple frameworks.
- the embodiment of the present application provides a sub-application loading method, the method is executed by an electronic device, and should be configured as a micro-front-end system, and the micro-front-end system includes: a routing registration service, a sub-application loading module, and a sub-application running module.
- the method include:
- URL Uniform Resource Locator
- the sub-application loading module acquires the sub-application resource corresponding to the routing information from the routing registration service based on the routing information;
- the sub-application loading module loads the sub-application resource
- the sub-application running module runs the sub-application resource, and renders the page of the sub-application.
- Embodiments of the present application provide a computer-readable storage medium, which stores executable instructions and is configured to implement the foregoing method for loading sub-applications based on a micro-front-end system when executed by a processor.
- An embodiment of the present application provides an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to execute the above-mentioned method for loading sub-applications based on a micro-front-end system through the computer program.
- Embodiments of the present application provide a computer program product, including a computer program, which implements the above-mentioned method for loading sub-applications based on a micro-front-end system when the computer program is executed by a processor.
- the micro-front-end system provided in the embodiment of this application includes a routing registration service, a command-line tool, and a micro-front-end operating framework, and maintains and operates the Node back-end service independently, so that it can provide good capacity expansion and disaster tolerance.
- the micro-front-end running framework of the main application provides routing information, loading methods and deployment information of sub-applications; provides new sub-applications, access sub-applications, and service registration functions through command-line tools; provides sub-applications under multiple frameworks operational capability.
- FIG. 1 is a schematic diagram of the composition and structure of a micro-front-end system provided by an embodiment of the present application
- FIG. 2 is a schematic diagram of another composition structure of a micro-front-end system provided by an embodiment of the present application.
- FIG. 3 is a schematic flowchart of the implementation of the method for loading sub-applications based on a micro-front-end system provided by an embodiment of the present application;
- FIG. 4 is a schematic flowchart of another implementation of a method for loading sub-applications based on a micro-front-end system provided by an embodiment of the present application;
- FIG. 5 is a schematic flowchart of the implementation of the sub-application loading method based on the micro front-end system provided by the embodiment of the present application;
- FIG. 6 is a schematic diagram of a micro-front-end system architecture provided by an embodiment of the present application.
- FIG. 7 is a schematic diagram of a communication mechanism in a micro-front-end system provided by an embodiment of the present application.
- FIG. 8 is a schematic flowchart of the implementation of the sub-application loading module for loading sub-application resources according to an embodiment of the present application
- FIG. 9 is a schematic design diagram of a JS sandbox provided by an embodiment of the present application.
- FIG. 10 is a schematic diagram of application layers provided by an embodiment of the present application.
- Vue framework It is a set of progressive front-end frameworks for building user interfaces. The core library of Vue only focuses on the view layer.
- React framework It is a JavaScript (JS) library configured to build a user interface. It is mainly configured to build a user interface. React can pass various types of parameters, such as declaring code, rendering the user interface, or static elements, or Dynamic variables and even interactive application components can be passed.
- JS JavaScript
- JavaScript sandbox mechanism It is a security mechanism that provides an isolated environment for running programs. It runs JS code by providing an execution environment that is isolated from the outside world. It is often used in micro-frontends to help independent online code that does not interfere with each other. , decoupling and reducing maintenance costs.
- Web Worker It is a JavaScript multi-threaded solution provided by HyperText Markup Language (HTML, HyperText Markup Language) 5, which can hand over some computationally intensive code to the Web Worker to run without freezing the user interface. It is independent of other scripts and does not affect the performance of the page.
- HTML HyperText Markup Language
- Shadow Dom Shadow Document Object Model
- HTML Tags Cascading Style Sheets
- CSS Cascading Style Sheets
- JavaScript code JavaScript code
- Props transmission The template of the parent component contains child components.
- the parent component must forward data or parameters to the child component. After the child component receives it, it renders different content or performs operations according to the parameters. This forward The process of passing data is achieved through Props.
- Custom Event transmission The interaction between JavaScript and HTML is achieved through events. Events are some specific interaction moments that occur in the document or browser window. JavaScript can trigger specific automatic events at any time. Define events, and these events are the same as those created by the browser.
- Sending messages PostMessage It is an application program interface method introduced by HTML5. It supports scripts from different sources to communicate effectively in an asynchronous manner. It can realize cross-text document, multi-window and cross-domain message delivery, and is configured for inter-window data communication. This also makes it an efficient solution for cross-domain communication.
- Iframe is a hypertext markup language tag configured to create an inline frame (ie, inline frame) containing another document.
- Node.js It is a JavaScript runtime environment based on the Chrome V8 engine. It uses an event-driven, non-blocking I/O model to allow JavaScript to run on the server-side development platform. It makes JavaScript a development platform that is compatible with PHP, Python, Perl , Ruby and other server-side languages are on an equal footing with scripting languages.
- Polyfilling Indicates that a method already exists in the JavaScript specification, but a specific JavaScript engine does not yet support the method, so it can be implemented manually and used to fill the built-in prototype.
- Single-SPA It is a set of micro-front-end framework, which takes over browser address switching to achieve the purpose of switching applications, and also manages the life cycle of each application from startup to destruction, and additional functions can be added during the change of the life cycle. (eg animation), and Single-SPA also provides plugins for different SPA frameworks to integrate existing applications.
- Micro front-end including the main application and sub-applications, is a slice that divides the application into multiple vertical parts, and each slice is built from the underlying database to the upper user interface.
- the main application is a framework, which mainly integrates login, menu, navigation, and provides global data and public methods, while specific functional modules are implemented in sub-applications as much as possible.
- the functions of the main application may include: login, menu and navigation; the functions of the sub-application may correspond to specific page content.
- FIG. 10 is a schematic diagram of application layers provided by the embodiment of the present application.
- the back-pipe system requires login authentication, and has a menu bar on the left and a personal information navigation bar above. , the middle part is the specific page content. Based on this feature, the back management system can be divided into two parts: the main application (login module + menu module + navigation module) and the sub-application (specific content page module).
- the positioning of the main application is the main frame, which mainly integrates the login module, menu module, and navigation module, and provides global data and public methods.
- the sub-application needs to consider additional independence. If it is in a micro-frontend environment, the sub-application is used as a whole application. Therefore, it will be closely related to the main application, but the sub-application itself should be relatively independent, and it can also run independently of the main application.
- the sub-application can be integrated into the main application and run in a micro-frontend architecture. , and can also be run independently from the main application, for example, the main application is a web page search application, and the sub-application is an advertisement recommendation application, a hot search application, and the like.
- the routing service uses Nginx service forwarding, which is inefficient.
- the central routing relies on the stability of the Nginx service, and the disaster recovery solution is complex.
- the cost is high and the communication mechanism is single, which will make it difficult to manage events after too many applications.
- Iframe as the application loader lacks the ability to arrange and control sub-applications.
- the micro-frontend solution of the related art does not consider the running ability of sub-applications under the multi-frontend framework, the activation ability of sub-applications under multi-level routing, and the ability of sub-applications to actively invoke activation through the main application; it does not provide cross-domain resources.
- the solution does not solve the problem that the front-end calls resources across domains after the distributed deployment of resources, including but not limited to interface requests, private static resources, and content delivery networks (CDN, Content Delivery Network). ) static resources, Web Worker resources, etc.
- CDN Content Delivery Network
- the embodiments of the present application provide a micro-front-end system, which provides an application loader module configured to load front-end applications of different frameworks, such as Vue framework, React framework, etc.; implements a JavaScript sandbox mechanism to ensure JS environment isolation; the system also Provides cross-domain processing of sub-application Web Worker, and implements CSS isolation by packaging and injecting CSS prefixes in sub-applications, injecting CSS prefixes when sub-applications are running, and loading sub-applications in Shadow Dom mode.
- Three parent-child application communication mechanisms provide a route registration service, provide centralized route discovery capabilities, and are compatible with running under the original Iframe.
- FIG. 1 is a schematic diagram of the composition and structure of the micro-front-end system provided by the embodiment of the present application.
- the micro-front-end system 100 includes: a route registration service 101 , command line tool 102 and micro-front-end running framework 103, wherein the routing registration service 101 is a Node back-end service that maintains and runs independently, and is configured to provide routing information of sub-applications and loading of sub-applications to the micro-front-end running framework of the main application mode and deployment information for sub-applications.
- a route registration service as a Node service that can be maintained and operated independently, it provides good expansion and disaster recovery capabilities, and maintains the registration and loading routes of sub-applications of the micro-frontend.
- the route registration service can be a server that provides a Hyper Text Transfer Protocol (HTTP, Hyper Text Transfer Protocol) service.
- HTTP Hyper Text Transfer Protocol
- it can be implemented by Node.js, and a set of record routes, delete routes, and queries can be implemented through the Koa framework.
- the web server for routing, login authorization and other functions, and the database uses a relational database management system (such as MySQL).
- the route registration service 101 can be a service that implements the same function by any server or language, such as Java Spring Cloud, C++ Server Kit, etc.
- routing registration service is a Node back-end service that is maintained and operated independently
- a load balancing service can also be placed in front of the routing registration service. After obtaining network requests, network requests can be distributed based on the load of each routing registration service. It can also provide good capacity expansion and disaster recovery capabilities when the load of multiple routing registration services is large.
- the command line tool 102 is configured to provide a function of creating a sub-application, a function of accessing a sub-application, and a function of service registration through a command line.
- a tool for a user to interact with a command line can be provided through Inquirer.js.
- the command line tool can be a command-line interface (CLI, command-line interface) tool, and also It can be an npm library or a graphical user interface (GUI, Graphical User Interface) tool.
- CLI command-line interface
- GUI graphical user interface
- the command line tool 102 can receive commands input by the user such as creating a sub-application and accessing a sub-application, and perform service registration based on the received commands.
- the micro-frontend running framework 103 is a framework running on the main application, configured to load and run sub-applications based on the obtained network request, and can provide the sub-application running capability under multiple frameworks.
- the main application is also an application that arbitrarily accesses the micro-frontend running framework.
- the micro-frontend running framework can be based on Single-SPA to provide multi-framework sub-application loading capabilities.
- the micro-front-end system includes a routing registration service, a command-line tool, and a micro-front-end running framework, wherein the routing registration service is a Node back-end service that is maintained and operated independently, which can provide good capacity expansion and disaster tolerance.
- the routing registration service provides the routing information, loading method, and deployment information of the sub-application for the micro-front-end running framework of the main application;
- the command line tool is configured to provide new sub-applications, access sub-applications, and service registration through the command line.
- micro-frontend running framework which is the framework running on the main application, is configured to load and run sub-applications based on the obtained network requests, and can provide the ability to run sub-applications under multiple frameworks.
- the micro-front-end system further includes: a front-end interface 104 corresponding to the routing registration service, obtains the sub-application registration information that needs to be set for sub-application registration through the front-end interface 104, and registers the sub-application The information is sent to the route registration service.
- the sub-application registration information includes: a sub-application framework, a sub-application routing mode, and a sub-application loading mode.
- the sub-application framework may include Vue, React, etc.
- the sub-application routing mode may include hash mode, history mode, etc.
- the sub-application loading mode may include: JS loading mode, CSS loading mode, HTML loading mode Wait.
- the sub-application registration information may further include the service name, the sub-application local development environment address, the sub-application online environment address, and the like.
- the route registration service 101 is configured to receive sub-application registration information, and register the sub-application based on the sub-application registration information.
- the command line tool 102 is configured to receive a new sub-application command, and obtain routing information, resource information and sub-application template information of the sub-application.
- the routing information of the sub-application may include: the sub-application resource address and the sub-application resource registration path, the resource information of the sub-application may include the sub-application resource name and the sub-application resource type, and the sub-application template information may include the template identifier. .
- the command line tool 102 generates a sub-application template based on the sub-application template information, and sends a sub-application creation request to the route registration service 101, where the sub-application creation request carries routing information and resource information.
- the route registration service 101 after receiving the sub-application creation request, creates a sub-application based on the routing information and resource information carried in the sub-application creation request.
- the command-line tool 102 sends a sub-application creation request to the routing registration service
- the command-line tool 102 sends a sub-application deployment request to the deployment server
- the deployment server performs resource deployment based on the sub-application resource address in the deployment request .
- the command line tool 102 is further configured to receive an access sub-application command, obtain routing information and resource information of the sub-application, and send a sub-application access request to the routing registration service 101, where the sub-application access request is It carries the routing information and resource information of the sub-application;
- the routing registration service 101 is further configured to receive a sub-application access request, and perform sub-application registration based on the routing information and resource information of the sub-application.
- the composition structure of the micro-frontend running framework 103 shown in FIG. 1 is shown in FIG. 2 and includes: a basic function library module 1031, a communication module 1032, a unified routing module 1033, a sub-application loading module 1034, and a sub-application running module 1035, of which:
- the basic function library module 1031 is configured to provide public methods and public components, and inject the public methods and public components into the sub-application by means of global variables and functions for use by the sub-application.
- the basic function library module may also provide common polyfilling for sub-applications to use.
- the communication module 1032 is configured to support communication mechanisms of main application to sub-application, sub-application to sub-application and sub-application to main application.
- the communication mechanism from the main application to the sub-application includes props transmission and custom event Custom Event transmission
- the communication mechanism from the sub-application to the sub-application includes asynchronous PostMessage transmission of different source scripts
- the communication between the sub-application and the main application Mechanisms include Custom Event transmission.
- Props transmission can provide responsive two-way data transmission capabilities
- Custom Event can define the distribution and registration of events based on components, avoiding the impact of irrelevant events after too many applications
- PostMessage provides global event sending and receiving, which is used to implement broadcast-type message notification .
- there are corresponding implementation solutions in each communication dimension the means are abundant, and the side effects are small.
- This embodiment of the application provides three types of communication support, including Props transmission, Custom Event transmission, and PostMessage transmission.
- Props transmission can provide responsive two-way data transmission capability
- Custom Event transmission can define event distribution and registration based on components, avoiding too many applications.
- PostMessage transmission provides global event sending and receiving, and is configured to implement broadcast-type message notifications. There are responsive implementation schemes in each communication dimension, with rich means and small side effects.
- the unified routing module 1033 is configured to monitor browser routing changes.
- the unified routing module 1033 uses Single-SPA to monitor browser routing changes, load, activate, and run sub-applications or main application sub-paths under the specified framework.
- the unified routing module is pulled from the routing registration service. Sub-application registration path, resources and other information under 1033.
- the sub-application loading module 1034 is configured to acquire and load the resource corresponding to the sub-application resource address based on the sub-application resource address obtained from the routing registration service.
- the sub-application loading module 1034 when the sub-application loading module 1034 loads the resource corresponding to the sub-application resource address, it will load the sub-application resource according to the sub-application loading mode in the sub-application registration information, wherein the sub-application loading module loads the mode of the sub-application At least include HTML entity mode, JS entity mode and Iframe mode.
- the loading mode is HTML entity mode
- the HTML file is loaded.
- the loading mode is JS entity mode
- the JS file is loaded.
- the loading mode is Iframe mode
- the URL is directly embedded in the Iframe to open.
- the sub-application loading module 1034 after acquiring the resource corresponding to the sub-application resource address, acquires the service code of the sub-application based on the resource, parses the acquired service code of the sub-application, and parses the The latter service code is transmitted to the sub-application running module 1035 .
- the sub-application running module 1035 is configured to run the resource corresponding to the resource address of the sub-application to render the sub-application page.
- the sub-application running module 1035 includes a running environment sandbox, obtains the parsed business code from the sub-application running module, and executes the parsed business code in the running environment sandbox.
- the runtime environment sandbox includes: JS sandbox, CSS sandbox, and Web Worker sandbox.
- JS sandbox Use with statement and proxy to implement basic JS sandbox, achieve basic security under controllable sub-applications, and overcome scope escape methods through stack checking and keyword checking.
- the proxy is a collection of objects accessible to the sub-application
- the JS sandbox enables the business code of the sub-application to access only the objects accessible in the proxy, but not the objects of other sub-applications or the main application.
- the parsed business code When the parsed business code is executed in the JS sandbox, the parsed business code is put into the sandbox with the proxy as the global root object for execution, that is to say, the business code can only access the objects and properties of the proxy without affecting the To other variables in the outer layer, to achieve safe isolation.
- Three CSS sandbox methods are provided in the embodiments of the present application: one is based on the sub-application webpack packaging prefix, and the sub-application webpack packaging prefix is to assign a separate namespace to the styles of each sub-application, so as to avoid styles affecting each other; Based on the runtime prefix of the sub-application, dynamically add a prefix to the style of the sub-application when the sub-application is running to avoid style conflicts; the third is based on Shadow Dom, and the CSS sandbox based on Shadow Dom can provide browser-level style isolation capabilities. Complete isolation is possible.
- the Web Worker sandbox is configured to run the script files assigned to the Web Worker inline to implement cross-domain calls of the Web Worker.
- the sub-application resource loading module hijacks the *.worker.js file when loading resources, loads the file back into the browser memory as text content, and uses the Web Worker sandbox to run the Web Worker script file (*.worker.js inline) ), the inline running Web Worker script file will not cause cross-domain problems, thus solving the cross-domain problem of Web Worker.
- the micro-frontend system further includes a server that supports cross-domain resource sharing.
- the server automatically carries the Cross-origin Resource Sharing (CORS, Cross-origin Resource Sharing) header, so that it can support cross-origin resource sharing, allowing browsers to access private static resources and CD N static resources across domains.
- CORS Cross-origin Resource Sharing
- the embodiment of this application provides a server-side CORS solution including interface resources to support cross-domain, CDN static resources provide a CORS solution, and Web Worker provides an inline build loader and an inline run loader to solve the problem of calling workers across domains.
- the embodiments of the present application also provide means such as caching, preloading, and Web Worker to accelerate the loading and invocation of sub-applications.
- the micro-frontend running framework 103 further includes: a data management module 1036, a performance monitoring module 1037 and an error handling module 1038, wherein:
- the data management module 1036 is configured to implement the data two-way binding function through the data provided by the Props transmission mechanism, so as to share the data of the parent and child applications.
- the main application when the parent and child applications are loaded in the same operating environment, the main application will pass an object with a monitoring function to the child application, and the change of the child application can be monitored by the object, so that the parent-child application can be realized. sharing of data.
- the performance monitoring module 1037 is configured to monitor the loading duration and running duration of the sub-application.
- the main application monitors information such as the loading time and running time of the sub-applications through preset functions.
- the error handling module 1038 is configured to monitor and process error information of the sub-application during the loading and running process.
- the main application monitors and handles sub-application errors by registering window.addEventListener('error', errorHandler) and window.addEventListener('unhandledrejection', errorHandler), so that the error information of the sub-application can be processed in time to ensure the micro-frontend. system reliability.
- this embodiment of the present application further provides a method for loading sub-applications based on the micro-front-end system, which should be configured as the micro-front-end system provided by the foregoing embodiments.
- Step S301 acquiring a network access request.
- the network access request carries a URL address.
- the network access request may be triggered by a user's network access operation.
- the functional network access request may be a request configured to access the main application, or may be a request to access a sub-application.
- the network access request is a network access request for accessing a sub-application, it may be that the user enters the URL address of the main application in the browser, and after the browser renders the main application interface, the user can use the sub-application provided in the main application interface. icon to trigger a network access request to the child application.
- the micro front-end system before step S301, has completed the deployment of the main application and the routing registration service, and has completed the creation and registration of the sub-application through the CLI tool.
- step S302 corresponding routing information is pulled from the routing registration service of the micro front-end system based on the URL address.
- the URL address may be sent to the routing registration service, and the routing registration service determines the application identifier to be accessed according to the URL address, and then pulls the corresponding routing information based on the application identifier.
- Step S303 when it is determined based on the routing information that the page to be accessed is a sub-application page, the sub-application loading module of the micro front-end system obtains the sub-application resource corresponding to the routing information from the routing registration service based on the routing information.
- the routing registration service can obtain the corresponding sub-application resources according to the routing information, such as CSS, JS and other static resources. document.
- Step S304 when the sub-application resource needs to be loaded, the sub-application loading module loads the sub-application resource.
- the sub-application loading module after acquiring the sub-application resource, the sub-application loading module first determines whether the sub-application resource needs to be loaded, and then loads the sub-application resource based on the sub-application loading mode when the sub-application resource needs to be loaded. When it is determined that the sub-application resource does not need to be loaded, it indicates that the sub-application resource has been loaded, and the sub-application resource is directly run to render the sub-application page.
- Step S305 the sub-application running module of the micro front-end system runs the sub-application resources to render the page of the sub-application.
- the sub-application loading module acquires the service code of the sub-application based on the sub-application resource, parses the acquired service code of the sub-application, and stores the parsed service code Transfer to the sub-application running module.
- the sub-application running module obtains the parsed business code, and executes the parsed business code in the sandbox of its own running environment to render the page of the sub-application.
- the runtime environment sandbox includes: JS sandbox, CSS sandbox, and Web Worker sandbox.
- JS sandbox use the with statement and proxy to implement the basic JS sandbox, achieve basic security under the control of sub-applications, and overcome the scope escape method through stack checking and keyword checking.
- the proxy is a collection of objects accessible to the sub-application
- the JS sandbox enables the business code of the sub-application to only access the objects accessible in the proxy, and cannot access the objects of other sub-applications or the main application.
- the parsed business code When the parsed business code is executed in the JS sandbox, the parsed business code is put into the sandbox with the proxy as the global root object for execution, that is to say, the business code can only access the objects and properties of the proxy without affecting the To other variables in the outer layer, to achieve safe isolation.
- Three CSS sandbox methods are provided in the embodiments of the present application: one is based on the sub-application webpack packaging prefix, and the sub-application webpack packaging prefix is to assign a separate namespace to the styles of each sub-application, so as to avoid styles affecting each other; Based on the runtime prefix of the sub-application, the conflict of styles is avoided by dynamically loading and unloading the application style at the runtime of the sub-application; the third is based on Shadow Dom, and the CSS sandbox based on Shadow Dom can provide browser-level style isolation capabilities, which can be completely isolation.
- the Web Worker sandbox is configured to run the script files assigned to the Web Worker inline to implement cross-domain calls of the Web Worker.
- the sub-application resource loading module hijacks the *.worker.js file when loading resources, loads the file back into the browser memory as text content, and uses the Web Worker sandbox to run the Web Worker script file (*.worker.js inline) ), the inline running Web Worker script file will not cause cross-domain problems, thus solving the cross-domain problem of Web Worker.
- the sub-application loading module of the micro-front-end system obtains the sub-application resource corresponding to the routing information from the routing registration service based on the routing information, and when the sub-application resource needs to be loaded, the sub-application The loading module loads the sub-application resources, and then the sub-application running module of the micro front-end system runs the sub-application resources to render the page of the sub-application.
- the sub-application loading method based on the micro front-end system further includes:
- Step S003 it is determined whether the sub-application resource is preloaded or whether it is opened.
- step S304 when the sub-application resource has not been preloaded and has not been opened, it is determined that the sub-application resource needs to be loaded, and step S304 is entered at this time; when the sub-application resource has been preloaded or opened, it is determined that the sub-application resource is not It needs to be loaded again, in this case, go to step S305. This can speed up the loading and invocation of sub-applications.
- the sub-application needs to be registered and deployed, and the sub-application registration process can be implemented through the following steps:
- Step S001 acquiring sub-application registration information that needs to be set for sub-application registration, and sending the sub-application registration information to a routing registration service.
- the sub-application registration information includes at least: a sub-application framework, a sub-application routing mode, and a sub-application loading mode.
- the micro-front-end system may include a front-end interface corresponding to the routing registration service, and may also include command-line tools configured to create new sub-applications and access sub-applications.
- step S001 when step S001 is implemented, there are two implementation modes:
- the front-end interface When obtaining the sub-application registration information based on the first method, the front-end interface is first presented based on the operation instruction for opening the front-end interface, and then an input operation for sub-application registration is received through the front-end interface, and the input operation is inputting the sub-application registration.
- Parameters that need to be set can include: service name, sub-application framework, sub-application local development environment address, sub-application online environment address, sub-application registration sub-route, sub-application routing mode (hash or history), sub-application loading mode Wait.
- the front-end interface is further provided with a graphic control for determining registration. After the user determines to complete the setting of the registration information of the sub-application, the user can click or touch the graphic control to send the registration information of the sub-application to the routing registration. Serve.
- the sub-application registration information is sent to the routing registration service, an HTTP request for sub-application registration may be sent to the routing registration service, and the HTTP request may carry the sub-application registration information.
- the command-line tool when obtaining the registration information of the sub-application based on the command-line tool, the command-line tool must be started first, and then the command-line tool is used to receive the new sub-application command, and then the input operation for the newly-created sub-application is obtained.
- the input operation is to input the parameters that need to be set for the registration of the sub-application, and then obtain the registration information of the sub-application according to the input operation.
- a command to send information may be input, and the sub-application registration information is sent to the route registration service based on the command to send information.
- Step S002 the routing registration service receives the sub-application registration information, and registers the sub-application based on the sub-application registration information.
- the routing information and resource information of the sub-applications can be registered by themselves, thereby improving the flexibility of registering the sub-applications.
- step S304 shown in FIG. 3 when the sub-application resource needs to be loaded, the sub-application loads the resource and loads the sub-application resource" can be implemented by the following steps:
- Step S3041 when the sub-application resource needs to be loaded, the frame identifier of the sub-application and the resource loading mode are acquired.
- the frame identifier of the sub-application may include Vue, React, etc.
- the resource loading mode may include: JS entity loading mode, CSS entity loading mode, Iframe loading mode, and the like.
- Step S3042 according to the resource loading type, load the sub-application resource in the sub-application frame corresponding to the frame identifier.
- the loading mode is HTML entity mode
- the HTML file is loaded
- the loading mode is JS entity mode
- the JS file is loaded
- the loading mode is Iframe mode
- the URL is directly embedded in the Iframe to open.
- step S302 the following steps may also be performed:
- Step S201 determining whether the page to be accessed is the main application page based on the routing information.
- step S202 when it is determined based on the routing information that the page to be accessed is the main application page, step S202 is performed; when it is determined based on the routing information that the page to be accessed is a sub-application page, step S303 is performed.
- Step 202 Determine the sub-application currently mounted by the main application according to the life cycle.
- Step S203 determining the target sub-application to be rendered from the currently mounted sub-applications.
- step S203 may be to determine at least one target sub-application to be rendered from the currently mounted sub-applications according to a preset rule, for example, it may be to select one or more target sub-applications with the most access times from the currently mounted sub-applications to determine for the target sub-application.
- Step S204 based on the exposed loading function and the target sub-application, simulate route switching, and acquire sub-application resources and main application resources of the target sub-application.
- the main application resources are first obtained according to the routing information.
- the loading function since the loading function is exposed, the loading function can be actively called by the main application.
- route switching can be simulated, thereby triggering the sub-application loading module of the micro-frontend system to obtain the target sub-application.
- the app's sub-app resources are first obtained according to the routing information.
- Step S205 load and run the main application resource and the sub-application resource, so as to render the sub-application in the rendered page of the main application.
- step S205 When step S205 is implemented, first load and run the main application resources to render the main application interface, and then run the sub-application resources, and also render the sub-application pages, so that the main application can actively render the sub-applications without relying on route registration. .
- the currently mounted sub-application when the page to be accessed is the main application page, the currently mounted sub-application may be determined according to the life cycle of the main application, and the target sub-application may be determined based on the preset principle, And by calling the exposed loading function, simulating route switching, obtaining the sub-application resources of the target sub-application, and displaying the sub-application page in the rendered main application page, so as to realize the active rendering of the sub-application by the main application.
- FIG. 6 is a schematic diagram of a micro-front-end system provided by an embodiment of the present application.
- the micro-front-end system includes: a routing registration service 601 and a front-end page corresponding to the routing registration service, sub-application access and a generated CLI tool 602 .
- the routing registration service 601 provides the micro-frontend running framework 603 with routing information of the sub-application, loading method, and deployment information of the sub-application.
- a front-end interface can be provided for sub-application routing registration, through which parameters required for routing registration can be set.
- the parameters to be set include but are not limited to: service name, sub-application framework, sub-application local development environment address, sub-application online environment address, sub-application registration sub-route, sub-application routing mode (hash or history), sub-application loading mode.
- Route registration service 601 is a server that provides HTTP services, mainly implemented by Node.js. It implements a set of web servers that record routing, delete routing, query routing, login authorization and other functions through the Koa framework.
- the database can use MySQL, or you can use other forms of databases.
- the route registration service can be a Node backend service, through which the registration information of the sub-application is received, the application loader parses and discovers the sub-application through the Node back-end service, and determines how to load the sub-application through the information Resources. Multiple Node single services are started through PM2.
- PM2 is a Node application process manager with load balancing function.
- the routing registration service can also include a load balancing service, which is configured to provide disaster recovery, liveness and capacity expansion capabilities of services.
- the CLI tool 602 provides functions including creating a sub-application, accessing a sub-application, service registration and deployment.
- a set of command-line tools are provided through Inquirer.js, including functions such as creating new sub-applications, accessing sub-applications, service registration and deployment.
- the user can first enter the new sub-application command on the command line, and fill in the sub-application resource name, sub-application resource address, sub-application resource type, and sub-application resource registration path, and select the sub-application template.
- CLI The tool automatically generates corresponding templates and injects routing information, and automatically registers resource information to the routing registration service.
- the user can enter the access sub-application command on the command line, and fill in the sub-application resource name, sub-application resource address, sub-application resource type, and sub-application resource registration path, and the CLI tool automatically finds the sub-application Enter the entry file, and add the life cycle functions required by the main application.
- the CLI tool automatically registers the resource information with the route registration service.
- the CLI tool When the service registration function is implemented, the CLI tool carries the new sub-application command, fills in the sub-application resource name, sub-application resource address, sub-application resource type, sub-application resource registration path and other parameters, and sends it to the routing registration service through an HTTP request.
- the CLI tool When the deployment function is implemented, the CLI tool sends a deployment request to the route registration service through an HTTP request.
- the micro-frontend running framework 603 is a framework that runs in the main application.
- the main application can also be called a parent application or an application shell (APP shell).
- the APP shell includes a public resource library, an application loader, and a resource loader (Single- SPA package) and the runtime environment sandbox.
- the runtime environment sandbox includes js sandbox, web worker inline sandbox and CSS environment isolation sandbox.
- the APP shell also supports running in Iframe mode.
- the main application is any application that accesses the micro-frontend running framework.
- the micro-frontend running framework includes a basic function library, a communication module, a data management module, a performance monitoring module, an error handling module, a unified routing module, a sub-application loading module, and a sub-application running module.
- the basic function library provides common polyfills, public methods and components, which are injected into sub-applications through global variables and functions for use by sub-applications.
- the communication module provides event communication through Custom Event, message communication through PostMessage, and system data communication through Props transmission in the life cycle.
- FIG. 7 is a schematic diagram of a communication mechanism in a micro-front-end system provided by an embodiment of the present application.
- the communication mode from the main application to the sub-application may include: two communication mechanisms: Props and Custom Event, and the sub-application to the main application
- the communication modes may include: Custom Event (component) and Custom Event (window) two communication mechanisms
- the communication modes between sub-applications include: PostMessage and Broadcast Channel (BroadcastChannel) two communication modes.
- the data management module through the data provided by Props, can realize the two-way data binding function and share the data of the parent and child applications.
- the performance monitoring module is configured to monitor the loading time, running time and other data of the sub-applications through the function of the main application.
- the error handling module is configured to monitor and handle the error information during the loading and running of the sub-application.
- the main application monitors and handles errors reported by the sub-application by registering listeners, where the registered listeners include window.addEventListener('error', errorHandler) and window.addEventListener('unhandledrejection', errorHandler).
- the unified routing module uses Single-SPA to monitor browser routing changes, loads and activates the sub-application or main application sub-path under the specified framework, and pulls the sub-application registration under the unified routing module from the routing registration service when the main application is initialized. Information such as paths, resources, etc.
- Sub-application loading module configured to load sub-application resources.
- FIG. 8 is a schematic diagram of the implementation process of loading sub-application resources by a sub-application loading module provided by an embodiment of the present application. As shown in FIG. 8 , the process includes:
- Step S801 based on the acquired network request, pull the route and static resources from the route registration service.
- the network request carries a URL address.
- the application identifier corresponding to the URL address may be determined from the route registration service based on the URL address, and the route registration service may then determine the corresponding routing information according to the application identifier. , and obtain static resources based on routing information.
- Step S802 the resource loader loads sub-application resources.
- the resource loader can load sub-applications of different frameworks, and can load HTML Entry, JS Entry mode and Iframe mode.
- HTML mode loads static files through reference resources in HTML
- js mode loads resources dynamically through js, and also provides traditional Load sub-apps in Iframe mode.
- the resource loader may also provide means such as preloading, caching, and idle loading.
- Step S803 after the resource loader loads the sub-application resource, perform resource information registration.
- the resource loader loads the sub-application resources
- the loaded sub-application resource information is registered in the memory.
- the sub-application loading module includes a resource loader and a resource loader.
- the resource loader is based on the Single-SPA encapsulation, which can provide the sub-application running capability under the multi-frontend framework.
- the Single-SPA provides the function of route monitoring. When the route is switched, the framework code and business code of the corresponding sub-application will be loaded according to the life cycle, so as to realize the ability to run different frameworks and multi-level routing activation; and by exposing the loading function to simulate the route switching, the main application can actively call the activation ability.
- the sub-application running module includes JS sandbox and CSS sandbox (non-traditional Iframe mode exists), and the sub-application running module is responsible for loading the js resources pulled back by the sub-application loading module.
- the JS sandbox design is shown in Figure 9.
- the with function 901 and the proxy 902 are used to implement the basic js sandbox.
- the proxy proxy and snapshot proxy modes can be implemented, and the snapshot proxy mode is compatible with environments that do not support ES6Proxy.
- the actual code 903 of the sub-application parsed by the resource loader of the application loader is put into the proxy sandbox for execution.
- stack checking and keyword checking are used to prevent them, so as to achieve basic security under the control of sub-applications.
- Sub-applications need to uniformly access packaging tools, and assign a separate namespace to the styles of each sub-application;
- Shadow Dom needs to deal with shadow boundaries, event loss, access control (shadowRoot) and other issues.
- the micro-frontend system provided by the embodiments of this application provides a route registration service, as a Node service that can be maintained and operated independently, provides good capacity expansion, disaster tolerance, and maintains the registration and loading routes of sub-applications of the micro-frontend; and based on Single -SPA provides the ability to run sub-applications under multiple frameworks. Based on a customized loading scheme, it provides the ability for the main application to actively render sub-applications, and does not necessarily need to rely on routing registration; in addition, three types of communication support are provided in the communication mechanism, including Props transfer, Custom Event, PostMessage, and Props transmission can provide responsive two-way data transmission capabilities. Custom Event can define the distribution and registration of events based on components, avoiding the impact of irrelevant events after too many applications.
- PostMessage provides global event sending and receiving, configured to achieve Broadcast message notifications have response implementation schemes in each communication dimension, with rich means and small side effects;
- the micro-front-end system provides server-side CORS solutions including interface resources to support cross-domain, private static resources, and CDN static resources.
- the CORS solution supports cross-domain.
- Web Worker provides inline build loader and inline runtime loader to solve the problem of calling workers across domains, and also provides caching, preloading, Web Worker and other means to accelerate the loading and invocation of sub-applications; and provides running The scheme of loading sub-applications at runtime can change the rendering content and interaction logic of sub-applications at runtime, providing higher freedom.
- Embodiments of the present application provide a computer program product or computer program, where the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
- the processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the micro-front-end system-based sub-application loading method described in the embodiments of the present application.
- Embodiments of the present application provide a storage medium storing executable instructions, where executable instructions are stored, and when the executable instructions are executed by a processor, the processor will cause the processor to execute the sub-application loading method provided by the embodiments of the present application, for example , the sub-application loading method shown in FIG. 3 , FIG. 4 and FIG. 5 .
- the storage medium may be a computer-readable storage medium, for example, Ferromagnetic Random Access Memory (FRAM), Read Only Memory (ROM), Programmable Read Only Memory (PROM). Read Only Memory), Erasable Programmable Read Only Memory (EPROM, Erasable Programmable Read Only Memory), Electrically Erasable Programmable Read Only Memory (EEPROM, Electrically Erasable Programmable Read Only Memory), Flash Memory, Magnetic Surface Memory, Optical Disc, Or memory such as CD-ROM (Compact Disk-Read Only Memory); it can also be various devices including one or any combination of the above memories.
- FRAM Ferromagnetic Random Access Memory
- ROM Read Only Memory
- PROM Programmable Read Only Memory
- EPROM Erasable Programmable Read Only Memory
- EEPROM Electrically Erasable Programmable Read Only Memory
- Flash Memory Magnetic Surface Memory
- Optical Disc Or memory such as CD-ROM (Compact Disk-Read Only Memory); it can also be various devices including one or any combination of the above memories.
- executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and which Deployment may be in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
- executable instructions may, but do not necessarily correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, a Hyper Text Markup Language (HTML, Hyper Text Markup Language) document in one or more scripts, stored in a single file specifically configured for the program in question, or in multiple cooperating files (e.g., files that store one or more modules, subprograms, or portions of code) .
- executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or alternatively, distributed across multiple sites and interconnected by a communication network execute on.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Multimedia (AREA)
- Human Computer Interaction (AREA)
- Information Transfer Between Computers (AREA)
- Stored Programmes (AREA)
Abstract
Description
Claims (20)
- 一种微前端系统,所述微前端系统包括:路由注册服务、命令行工具和微前端运行框架,其中,所述路由注册服务,为独立维护运行的节点Node后端服务,配置为为主应用的微前端运行框架提供子应用的路由信息、所述子应用的加载方式和所述子应用的部署信息;所述命令行工具,配置为通过命令行提供新建子应用功能、接入子应用功能、服务注册功能;所述微前端运行框架,为运行在所述主应用的框架,配置为基于获取到的网络请求加载并运行所述子应用,并提供多框架下的子应用运行能力。
- 根据权利要求1中所述的微前端系统,其中,所述微前端系统还包括:与所述路由注册服务对应的前端界面,配置为获取针对子应用注册需要设置的子应用注册信息,并将所述子应用注册信息发送至所述路由注册服务,所述子应用注册信息包括:子应用框架、子应用路由模式、子应用加载模式;所述路由注册服务,还配置为接收所述子应用注册信息,并基于所述子应用注册信息注册所述子应用。
- 根据权利要求1中所述的微前端系统,其中,所述命令行工具,还配置为接收新建子应用命令,获取所述子应用的路由信息、所述子应用的资源信息和子应用模板信息;所述命令行工具,还配置为基于所述子应用模板信息生成子应用模板,并向所述路由注册服务发送子应用新建请求,所述子应用新建请求中携带有所述路由信息和所述资源信息;所述命令行工具,还配置为向部署服务器发送子应用部署请求,其中,所述子应用部署请求用于触发所述部署服务器基于所述子应用部署请求中的子应用资源地址进行资源部署。
- 根据权利要求2中所述的微前端系统,其中,所述命令行工具,还配置为接收接入子应用命令,获取所述子应用的路由信息和所述子应用的资源信息;所述命令行工具,还配置为向所述路由注册服务发送子应用接入请求,所述子应用接入请求中携带有所述子应用的路由信息和资源信息;所述路由注册服务,还配置为接收所述子应用接入请求,并基于所述子应用的路由信息和资源信息进行子应用注册。
- 根据权利要求1所述的微前端系统,其中,所述微前端运行框架包括:基础功能库模块、通信模块、统一路由模块、子应用加载模块和子应用运行模块,其中,所述基础功能库模块,配置为提供公共方法和公共组件,并通过全局变量和函数的方式将所述公共方法和所述公共组件注入到所述子应用,供所述子应用使用;所述通信模块,配置为支持所述主应用到所述子应用、所述子应用到所述子应用和所述子应用到所述主应用的通信机制;所述统一路由模块,配置为监听浏览器路由变更;所述子应用加载模块,配置为从所述路由注册服务获取子应用资源地址,获取并加载所述子应用资源地址对应的资源;所述子应用运行模块,配置为运行所述子应用资源地址对应的资源,并渲染出子应用页面。
- 根据权利要求5中所述的微前端系统,其中,所述主应用到子应用的通信机制包括道具Props传输和自定义事件Custom Event传输,所述子应用到子应用的通信机制包括发送消息PostMessage传输,所述子应用到主应用的通信机制包括Custom Event传输;所述子应用加载模块加载所述子应用的模式包括超文本标记语言HTML实体模式、脚本语言JS实体模式和页面嵌套Iframe模式。
- 根据权利要求5中所述的微前端系统,其中,所述微前端运行框架还包括:数据管理模块、性能监控模块、错误处理模块,其中:所述数据管理模块,配置为通过Props传输机制提供的数据,实现数据双向绑定功能;所述性能监控模块,配置为监控子应用的加载时长、运行时长;所述错误处理模块,配置为监控并处理子应用在加载和运行过程中的错误信息。
- 根据权利要求5中所述的微前端系统,其中,所述子应用加载模块,还配置为对获取到的所述子应用的业务代码进行解析,并将解析后的业务代码传输至所述子应用运行模块;所述子应用运行模块包括运行环境沙箱,所述解析后的业务代码在所述运行环境沙箱中执行。
- 根据权利要求8中所述的微前端系统,其中,所述运行环境沙箱包括:JS沙箱、层叠样式表CSS沙箱和后台脚本Web Worker沙箱。
- 根据权利要求9中所述的微前端系统,其中,所述Web Worker沙箱,配置为内联运行分配给Web Worker的脚本文件,并执行所述Web Worker的跨域调用。
- 根据权利要求1至10任一项所述的微前端系统,其中,所述微前端系统还包括支持跨域资源共享的服务器。
- 一种基于微前端系统的子应用加载方法,所述方法由电子设备执行,所述微前端系统包括:路由注册服务、子应用加载模块和子应用运行模块,所述方法包括:获取网络访问请求,所述网络访问请求中携带有待访问页面的统一资源定位符URL地址;基于所述URL地址从所述路由注册服务拉取对应的路由信息;当基于所述路由信息确定所述待访问页面为子应用页面时,所述子应用加载模块基于所述路由信息,从所述路由注册服务获取所述路由信息对应的子应用资源;当需要加载所述子应用资源时,所述子应用加载模块加载所述子应用资源;所述子应用运行模块运行所述子应用资源,并渲染出子应用的页面。
- 根据权利要求12中所述的方法,其中,所述方法还包括:确定所述子应用资源是否被预加载或者是否被打开;当所述子应用资源没有被预加载并且没有被打开时,确定所述子应用资源需要被加载。
- 根据权利要求12中所述的方法,其中,所述方法还包括:获取针对子应用注册需要设置的子应用注册信息,并将所述子应用注册信息发送至路由注册服务,所述子应用注册信息包括:子应用框架、子应用路由模式、子应用加载模式;通过所述路由注册服务接收所述子应用注册信息,并基于所述子应用注册信息注册所述子应用。
- 根据权利要求14中所述的方法,其中,所述获取针对子应用注册需要设置的子应用注册信息,包括:通过所述路由注册服务对应的前端界面,获取针对子应用注册的输入操作;基于所述输入操作确定所述子应用注册信息;或者,通过命令行工具接收新建子应用命令,获取所述子应用的路由信息、所述子应用的资源信息和子应用模板信息。
- 根据权利要求12中所述的方法,其中,所述当需要加载所述子应用资源时,所述子应用加载模块加载所述子应用资源,包括:当需要加载所述子应用资源时,获取所述子应用的框架标识和资源加载类型;根据所述资源加载类型,在所述框架标识对应的子应用框架中加载所述子应用资源。
- 根据权利要求12至16任一项所述的方法,其中,所述方法还包括:当基于所述路由信息确定待访问页面为主应用页面时,根据生命周期确定主应用当前挂载的子应用;从所述当前挂载的子应用中确定要渲染的目标子应用;基于暴露的加载函数和所述目标子应用,模拟路由切换,并获取所述目标子应用的子应用资源和主应用资源;加载并运行所述子应用资源和所述主应用资源,并在渲染出的所述主应用的页面中渲染出子应用。
- 一种计算机可读存储介质,存储有可执行指令,用于被处理器执行时,实现权利要求12至17任一项所述的基于微前端系统的子应用加载方法。
- 一种电子设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行所述权利要求12至17任一项中所述的基于微前端系统的子应用加载方法。
- 一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现权利要求12至17任一项所述的基于微前端系统的子应用加载方法。
Priority Applications (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
KR1020237010638A KR20230054474A (ko) | 2020-12-21 | 2021-12-10 | 마이크로프론트엔드 시스템, 서브애플리케이션 로딩 방법, 전자 디바이스, 컴퓨터 프로그램 제품 및 컴퓨터로 판독 가능한 저장 매체 |
JP2023515655A JP7451825B2 (ja) | 2020-12-21 | 2021-12-10 | マイクロフロントエンドシステム、サブアプリケーションロード方法、電子機器、及びコンピュータープログラム製品 |
US17/962,218 US20230036980A1 (en) | 2020-12-21 | 2022-10-07 | Micro-frontend system, sub-application loading method, electronic device, computer program product, and computer-readable storage medium |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011520184.6A CN114647518A (zh) | 2020-12-21 | 2020-12-21 | 微前端系统、子应用加载方法及计算机可读存储介质 |
CN202011520184.6 | 2020-12-21 |
Related Child Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
US17/962,218 Continuation US20230036980A1 (en) | 2020-12-21 | 2022-10-07 | Micro-frontend system, sub-application loading method, electronic device, computer program product, and computer-readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022135178A1 true WO2022135178A1 (zh) | 2022-06-30 |
Family
ID=81990618
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2021/137072 WO2022135178A1 (zh) | 2020-12-21 | 2021-12-10 | 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 |
Country Status (5)
Country | Link |
---|---|
US (1) | US20230036980A1 (zh) |
JP (1) | JP7451825B2 (zh) |
KR (1) | KR20230054474A (zh) |
CN (1) | CN114647518A (zh) |
WO (1) | WO2022135178A1 (zh) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115277637A (zh) * | 2022-09-26 | 2022-11-01 | 中企云链(北京)金融信息服务有限公司 | 基于微前端架构的多域名项目的管理平台及高度聚合部署方法 |
CN115828021A (zh) * | 2022-12-21 | 2023-03-21 | 北京深盾科技股份有限公司 | 一种网页通信方法、系统、电子设备及存储介质 |
CN115987959A (zh) * | 2022-12-02 | 2023-04-18 | 浪潮通信信息系统有限公司 | 一种基于远端加载的可定制app融合方法 |
CN116301870A (zh) * | 2023-05-17 | 2023-06-23 | 北京天信瑞安信息技术有限公司 | 微前端框架及其构建方法和相关设备 |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116501364B (zh) * | 2023-05-05 | 2024-06-07 | 南京领行科技股份有限公司 | 一种应用注册方法、装置和微前端系统 |
CN116301759B (zh) * | 2023-05-12 | 2023-11-03 | 国网信息通信产业集团有限公司 | 一种移动组件共享方法、系统、设备及存储介质 |
CN116506215B (zh) * | 2023-06-16 | 2023-09-12 | 中国联合网络通信集团有限公司 | 访问处理方法、装置、电子设备以及存储介质 |
CN116700834B (zh) * | 2023-08-07 | 2023-10-24 | 天津华来科技股份有限公司 | 一种App模块化加载方法及系统 |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20160092339A1 (en) * | 2014-09-26 | 2016-03-31 | Oracle International Corporation | Efficient means to test server generated applications on mobile device |
CN106598575A (zh) * | 2016-11-30 | 2017-04-26 | 武汉斗鱼网络科技有限公司 | 一种前端数据模拟的实现方法及系统 |
CN109542538A (zh) * | 2018-11-22 | 2019-03-29 | 郑州云海信息技术有限公司 | 一种子系统管理方法和系统 |
CN110377274A (zh) * | 2019-07-08 | 2019-10-25 | 紫光云技术有限公司 | 基于Single-Spa的微前端架构系统及开发、部署方法 |
CN110806895A (zh) * | 2019-11-04 | 2020-02-18 | 精硕科技(北京)股份有限公司 | 一种项目创建方法、装置及计算机可读存储介质 |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP4152755B2 (ja) | 2003-01-10 | 2008-09-17 | 富士通株式会社 | 新旧プログラムモジュールの切り替え機能を有するサーバ装置 |
US10678600B1 (en) | 2019-03-01 | 2020-06-09 | Capital One Services, Llc | Systems and methods for developing a web application using micro frontends |
CN110708368A (zh) | 2019-09-25 | 2020-01-17 | 北京计算机技术及应用研究所 | 一种基于路由分发的微前端系统和方法 |
CN111796860B (zh) | 2020-06-28 | 2024-01-30 | 中国工商银行股份有限公司 | 微前端方案实现方法及装置 |
-
2020
- 2020-12-21 CN CN202011520184.6A patent/CN114647518A/zh active Pending
-
2021
- 2021-12-10 JP JP2023515655A patent/JP7451825B2/ja active Active
- 2021-12-10 WO PCT/CN2021/137072 patent/WO2022135178A1/zh active Application Filing
- 2021-12-10 KR KR1020237010638A patent/KR20230054474A/ko unknown
-
2022
- 2022-10-07 US US17/962,218 patent/US20230036980A1/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20160092339A1 (en) * | 2014-09-26 | 2016-03-31 | Oracle International Corporation | Efficient means to test server generated applications on mobile device |
CN106598575A (zh) * | 2016-11-30 | 2017-04-26 | 武汉斗鱼网络科技有限公司 | 一种前端数据模拟的实现方法及系统 |
CN109542538A (zh) * | 2018-11-22 | 2019-03-29 | 郑州云海信息技术有限公司 | 一种子系统管理方法和系统 |
CN110377274A (zh) * | 2019-07-08 | 2019-10-25 | 紫光云技术有限公司 | 基于Single-Spa的微前端架构系统及开发、部署方法 |
CN110806895A (zh) * | 2019-11-04 | 2020-02-18 | 精硕科技(北京)股份有限公司 | 一种项目创建方法、装置及计算机可读存储介质 |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115277637A (zh) * | 2022-09-26 | 2022-11-01 | 中企云链(北京)金融信息服务有限公司 | 基于微前端架构的多域名项目的管理平台及高度聚合部署方法 |
CN115277637B (zh) * | 2022-09-26 | 2023-01-13 | 中企云链(北京)金融信息服务有限公司 | 基于微前端架构的多域名项目的管理平台及高度聚合部署方法 |
CN115987959A (zh) * | 2022-12-02 | 2023-04-18 | 浪潮通信信息系统有限公司 | 一种基于远端加载的可定制app融合方法 |
CN115828021A (zh) * | 2022-12-21 | 2023-03-21 | 北京深盾科技股份有限公司 | 一种网页通信方法、系统、电子设备及存储介质 |
CN115828021B (zh) * | 2022-12-21 | 2024-02-13 | 北京深盾科技股份有限公司 | 一种网页通信方法、系统、电子设备及存储介质 |
CN116301870A (zh) * | 2023-05-17 | 2023-06-23 | 北京天信瑞安信息技术有限公司 | 微前端框架及其构建方法和相关设备 |
Also Published As
Publication number | Publication date |
---|---|
JP2023541033A (ja) | 2023-09-27 |
CN114647518A (zh) | 2022-06-21 |
US20230036980A1 (en) | 2023-02-02 |
KR20230054474A (ko) | 2023-04-24 |
JP7451825B2 (ja) | 2024-03-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2022135178A1 (zh) | 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 | |
CN108319483B (zh) | 网页处理方法、装置、终端及存储介质 | |
US9672140B1 (en) | Processing special requests at dedicated application containers | |
US8266202B1 (en) | System and method for auto-generating JavaScript proxies and meta-proxies | |
US8285813B1 (en) | System and method for emulating different user agents on a server | |
JP5439190B2 (ja) | It向けサーバベースのウェブアプリケーションを作成するための方法およびシステム | |
US8639743B1 (en) | System and method for on-the-fly rewriting of JavaScript | |
US9798524B1 (en) | System and method for exposing the dynamic web server-side | |
US20080288622A1 (en) | Managing Server Farms | |
Lazuardy et al. | Modern front end web architectures with react. js and next. js | |
CN113010170A (zh) | 一种基于Vue3组件的页面渲染方法、装置、介质及电子设备 | |
CN114706579A (zh) | 页面开发方法、装置、服务器及存储介质 | |
Aguilar | SignalR Programming in Microsoft ASP. NET | |
Xu et al. | Caople: A programming language for microservices saas | |
Peters | Building rich internet applications with node. js and express. js | |
Larsson | Hands-on Microservices with spring boot and spring cloud: Build and deploy Java microservices using spring cloud, Istio, and Kubernetes | |
WO2022146714A9 (en) | System and method for real-time, dynamic creation, delivery, and use of customizable web applications | |
Jína | Javascript test runner | |
Nyfløtt | Optimizing inter-service communication between microservices | |
Hertel | Aspects of AJAX | |
Penberthy et al. | Serverless | |
Macero García et al. | Event-Driven Architectures | |
Sreekumar | Cross Platform Lightweight Social Networking Application for Next Generation E-Commerce | |
Lim et al. | Jda: a step towards large-scale reuse on the web | |
CN115982257A (zh) | 接口创建方法以及相关设备 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 21909175 Country of ref document: EP Kind code of ref document: A1 |
|
ENP | Entry into the national phase |
Ref document number: 2023515655 Country of ref document: JP Kind code of ref document: A |
|
ENP | Entry into the national phase |
Ref document number: 20237010638 Country of ref document: KR Kind code of ref document: A |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 21909175 Country of ref document: EP Kind code of ref document: A1 |
|
32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 021123) |