Method for remote component sharing mechanism at front-end runtime based on JS entry

Through the front-end runtime remote component sharing mechanism based on JS portal, the problem of independent operation and integration of sub-applications in complex front-end applications is solved, loose coupling relationship and independent operation are achieved, user experience is improved and business integration is simplified.

CN113064676BActive Publication Date: 2024-09-13SHANGHAI FINANCIAL FUTURES INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011594579.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-29
Publication Date
2024-09-13
Estimated Expiration
2040-12-29

AI Technical Summary

Technical Problem

In complex front-end applications, due to the diversity of business and team independence, users need to switch between multiple websites after the system is split, and the user experience is degraded. Collaboration and architecture optimization of each business team are difficult and impossible to achieve. A unified and friendly integrated website.

Method used

A front-end runtime remote component sharing mechanism based on JS entry is used to generate description files and entry files through the build phase. During the run phase, EventBus and DIV tags are used to realize independent running and uninstallation of sub-applications, avoiding dependency conflicts and ensuring that each sub-application is in the main application. China and China do not interfere with each other.

Benefits of technology

It realizes the independent development, deployment and operation of each sub-application, maintains loose coupling relationship, improves user experience, avoids dependency module and style conflicts, and simplifies business integration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113064676B
    Figure CN113064676B
Patent Text Reader

Abstract

The present invention discloses a method for a remote component sharing mechanism during front-end runtime based on a JS entry, so that each sub-application in the front-end application can be independently developed, independently deployed, and independently operated, and a loosely coupled relationship is maintained throughout the entire life cycle. The technical scheme is as follows: first, by constructing a JS immediate execution function mode, the dependent module is isolated by using the dependent module as a function parameter, so as to avoid the mutual influence of the dependencies of each sub-application in the main application. Secondly, the present invention uses the AST mode of CSS to add a namespace to each CSS selector, so that the styles of each sub-application are independent and will not conflict. The present invention generates a DIV tag at runtime, and notifies the DIV ID to the sub-application. After the sub-application obtains the ID, the rendering logic is executed, and the sub-application page is mounted in the corresponding DIV, so as to achieve the function of mounting multiple identical sub-application instances in one page and maintaining independent functions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a front-end application business development technology, and in particular to a technology based on JS entry, in which each business is regarded as a sub-application and is remotely loaded into a main application as a component during front-end runtime. Background Art

[0002] As more and more businesses are undertaken in a front-end application, the application becomes more and more complex, and different businesses involve different teams, the technical and management costs are huge, which often leads to the splitting of a large system. However, for users who use these business systems, for example, in the financial field, business personnel will use membership management, hedging arbitrage, market makers, investor education and training, etc. After the system is split, they need to switch back and forth between various websites to handle business, which reduces the user experience. Users have an urgent need for a unified and friendly integrated website, and the integration of each business front end involves communication and cooperation among various business teams, and architectural adjustment and optimization. Summary of the invention

[0003] A brief summary of one or more aspects is given below to provide a basic understanding of these aspects. This summary is not an exhaustive overview of all conceived aspects, and is neither intended to identify the key or critical elements of all aspects nor to define the scope of any or all aspects. Its only purpose is to give some concepts of one or more aspects in a simplified form as a prelude to a more detailed description that will be given later.

[0004] The purpose of the present invention is to solve the above problems and provide a method for a remote component sharing mechanism during the front-end runtime based on JS entry, so that each sub-application in the front-end application can be independently developed, deployed and run independently, maintaining a loosely coupled relationship throughout the entire life cycle.

[0005] The technical solution of the present invention is: the present invention discloses a method for a front-end runtime remote component sharing mechanism based on a JS entry, the method including processing in a construction phase and processing in a running phase, wherein:

[0006] The processing in the construction phase includes each sub-application generating its own description file and entry file in the construction phase. The entry file includes the JS entry file and the CSS entry file. The HTML elements in the front-end application are compiled into JS code and mixed into the JS resources. The CSS resources in the front-end application are loaded through the CSS entry file.

[0007] The processing flow of the operation phase includes:

[0008] Step 1: Start the main application and sub-applications. The main application generates a global EventBus instance.

[0009] Step 2: The main application loads the description file of the sub-application and obtains the sub-application name, resource address, and routing information data;

[0010] Step 3: The main application starts loading the module, which includes: the main application dynamically generates a DIV tag, the main application loads and executes the JS entry file and CSS entry file of the sub-application, when the sub-application JS is executed, it checks whether there is a global EventBus instance, if it exists, it uses the EventBus instance, if not, it actively generates an EventBus instance and uses it as the global EventBus instance, the main application notifies the sub-application of the identification number of the DIV tag through the initialization event in the form of an event, and different sub-applications listen to different event names;

[0011] Step 4: The sub-application listens to the initialization event, executes the rendering logic after receiving the notification of the ID sent by the main application, and mounts the HTML in the JS into the DIV tag corresponding to the ID, so that multiple identical sub-application instances can be mounted on one page and remain independent.

[0012] According to an embodiment of the method of the front-end runtime remote component sharing mechanism based on JS entry of the present invention, the description file is used for the main application to access the description files of each sub-application during the running stage, and the address of the entry file of each sub-application is obtained by identifying the description file information, wherein the description file contains data including the version number of the sub-application, the name of the sub-application, the resource address, and the routing information.

[0013] According to an embodiment of the method of the front-end runtime remote component sharing mechanism based on JS entry of the present invention, the entry file is used to load the entry file of the sub-application and execute the entry file when the main application loads the sub-application, and mount the sub-application to the designated area of ​​the main application.

[0014] According to an embodiment of the method of the front-end runtime remote component sharing mechanism based on JS entry of the present invention, the sub-application is packaged into static resources through the webpack packaging tool during the construction phase, and the JS entry file, CSS entry file, and description file are generated to complete the online deployment.

[0015] According to an embodiment of the method of the front-end runtime remote component sharing mechanism based on JS entry of the present invention, in the process of generating the entry file in the construction phase, the JS code is encapsulated by using the JS immediate execution function, and the dependent modules of the sub-application are used as parameters of the JS immediate execution function to generate the JS entry file, so that the JS of different sub-applications can only access the dependent modules of the sub-application, thereby avoiding the mutual influence of the dependencies of various sub-applications in the main application.

[0016] According to an embodiment of the method of the front-end runtime remote component sharing mechanism based on JS entry of the present invention, in the process of generating the entry file in the construction phase, the CSS file of the sub-application is parsed by AST, the name of the sub-application is added to the CSS selector, a new AST is generated, and finally the AST is converted into a CSS entry file.

[0017] According to an embodiment of the method of the front-end runtime remote component sharing mechanism based on JS entry of the present invention, the identification number of the DIV tag is a random number.

[0018] According to an embodiment of the method for the front-end runtime remote component sharing mechanism based on JS entry of the present invention, the method further includes:

[0019] Step 5: When the main application page is switched and the sub-application is no longer needed, the main application starts the process of uninstalling the sub-application: on the one hand, the main application notifies the sub-application through an event to perform the uninstallation, and then after the sub-application receives the uninstallation event notification from the main application, it processes its own uninstallation logic and completes the uninstallation; on the other hand, the main application actively removes the sub-application CSS resources.

[0020] Compared with the prior art, the present invention has the following beneficial effects: first, the present invention achieves dependency module isolation by constructing JS (JavaScript) to execute functions immediately and using dependent modules as function parameters, thereby avoiding the mutual influence of dependencies among sub-applications in the main application. Secondly, the present invention adds a namespace to each CSS selector by parsing the abstract syntax tree (AST, Abstract Syntax Tree) of Cascading Style Sheets (CSS), thereby achieving the independence of the styles of each sub-application without conflict. Finally, the present invention generates a DIV tag at runtime and notifies the sub-application of the DIVID. After the sub-application obtains the ID, it executes the rendering logic and mounts the sub-application page into the corresponding DIV, thereby achieving the function of mounting multiple identical sub-application instances in one page and maintaining independence. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The above features and advantages of the present invention can be better understood after reading the detailed description of the embodiments of the present disclosure in conjunction with the following drawings. In the drawings, the components are not necessarily drawn to scale, and components with similar related properties or features may have the same or similar reference numerals.

[0022] Figure 1 A flow chart of an embodiment of a method for a front-end runtime remote component sharing mechanism based on JS entry of the present invention is shown. DETAILED DESCRIPTION

[0023] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. Note that the aspects described below in conjunction with the accompanying drawings and specific embodiments are only exemplary and should not be construed as limiting the scope of protection of the present invention in any way.

[0024] The method of the front-end runtime remote component sharing mechanism based on the JS entry of this embodiment includes two parts: processing in the construction phase and processing in the running phase.

[0025] The build phase is processed as follows:

[0026] Each sub-application generates its description file and entry file during the build phase, where the entry file includes the JS entry file and the CSS entry file. The main application accesses the description files of each sub-application during the run phase, and obtains the address of each sub-application entry file by identifying the description file information. When the main application needs to load a sub-application, it loads the sub-application entry file and executes it, mounting the sub-application to the designated area of ​​the main application.

[0027] The basic elements of the front-end application include HTML, JS, and CSS resources. This embodiment uses the HTML in JS method to compile HTML elements into JS code and mix them into JS resources. CSS resources generally include elements such as font files and pictures, which makes the entire resource file too large. Retaining an independent CSS entry file can improve loading efficiency. This embodiment relies on the webpack packaging tool to package the sub-application into static resources during the construction phase, generate JS entry files, CSS entry files, and description files, and complete the online deployment.

[0028] In the process of generating the entry file, in order to ensure that each sub-application does not interfere with each other in the main application, it is necessary to resolve the conflict between JS and CSS. This embodiment resolves this conflict problem in the construction phase by encapsulating the JS code using the JS immediate execution function, taking the dependent module of the sub-application as the parameter of the JS immediate execution function, and generating the JS entry file, so that the JS of different sub-applications can only access the dependent module of the sub-application, avoiding the mutual influence of the dependencies of each sub-application in the main application.

[0029] On this basis, each business development team can achieve further decoupling during development. They do not need to unify the version number of a certain module and can develop sub-applications according to the technology stack of the business team. If the styles of different sub-applications affect each other, the entire display will be chaotic. This embodiment chooses to perform AST parsing on the CSS file of the sub-application during the sub-application construction phase, add the name of the sub-application to the CSS selector, generate a new AST, and finally convert the AST into a CSS entry file. Since each sub-application has a different name, each sub-application can be independent in style.

[0030] The description file contains data including the sub-application version number, sub-application name, resource address, and routing information.

[0031] Figure 1 The flow of an embodiment of the method for the front-end runtime remote component sharing mechanism based on JS entry in the running stage of the present invention is shown. Figure 1 The implementation steps of the method of this embodiment in the running stage are described in detail as follows.

[0032] Step 1: Start the main application and sub-application. The main application generates a global EventBus instance.

[0033] Step 2: The main application loads the description file of the sub-application and obtains the sub-application name, resource address, and routing information data.

[0034] Step 3: The main application starts loading the module.

[0035] The implementation of this step further includes:

[0036] The main application dynamically generates a DIV tag, where the ID of the DIV tag is a random number.

[0037] The main application loads and executes the JS and CSS entry files of the sub-application. When the sub-application JS is executed, it checks whether there is a global EventBus. If so, it uses the EventBus. If not, it actively generates an EventBus and uses it as the global EventBus.

[0038] The main application notifies the sub-application of the ID of the DIV tag through an event by initializing the event, wherein different sub-applications listen to different event names.

[0039] Step 4: The sub-application listens to the initialization event, executes the rendering logic after receiving the notification of the ID sent by the main application, and mounts the HTML in the JS into the DIV tag corresponding to the ID, so that multiple identical sub-application instances can be mounted on one page and remain independent.

[0040] Step 5: When the sub-application is no longer needed due to the main application page switching, the main application starts the process of uninstalling the sub-application.

[0041] Step 5 further includes the following two steps in parallel:

[0042] On the one hand, the main application notifies the sub-application to perform uninstallation through an event, and then executes step 6.

[0043] On the other hand, the main application actively removes the sub-application CSS resources.

[0044] Step 6: After receiving the uninstall event notification from the main application, the sub-application processes its own uninstall logic and completes the uninstallation.

[0045] Although the above methods are illustrated and described as a series of actions for simplicity of explanation, it should be understood and appreciated that these methods are not limited by the order of the actions, because according to one or more embodiments, some actions may occur in a different order and / or concurrently with other actions from those illustrated and described herein or not illustrated and described herein but understandable to those skilled in the art.

[0046] Those skilled in the art will further appreciate that the various illustrative logic blocks, modules, circuits, and algorithm steps described in conjunction with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or a combination of the two. To clearly illustrate this interchangeability of hardware and software, various illustrative components, blocks, modules, circuits, and steps are generally described above in terms of their functionality. Whether such functionality is implemented as hardware or software depends on the specific application and the design constraints imposed on the overall system. The technician may implement the described functionality in different ways for each specific application, but such implementation decisions should not be interpreted as resulting in a departure from the scope of the present invention.

[0047] The various illustrative logic blocks, modules, and circuits described in conjunction with the embodiments disclosed herein may be implemented or performed with a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general purpose processor may be a microprocessor, but in the alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in cooperation with a DSP core, or any other such configuration.

[0048] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software module may reside in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read and write information from / to the storage medium. In an alternative, a storage medium may be integrated into a processor. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In an alternative, the processor and the storage medium may reside in a user terminal as discrete components.

[0049] In one or more exemplary embodiments, the functions described may be implemented in hardware, software, firmware, or any combination thereof. If implemented as a computer program product in software, each function may be stored on or transmitted by a computer-readable medium as one or more instructions or codes. Computer-readable media include both computer storage media and communication media, including any medium that facilitates the transfer of a computer program from one place to another. Storage media may be any available medium that can be accessed by a computer. As an example and not limitation, such a computer-readable medium may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, disk storage or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer. Any connection is also properly referred to as a computer-readable medium. For example, if the software is transmitted from a website, a server, or other remote source using a coaxial cable, a fiber optic cable, a twisted pair, a digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwaves, the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwaves are included in the definition of the medium. Disk and disc as used herein include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, wherein disk often reproduces data magnetically, while disc reproduces data optically with lasers. Combinations of the above should also be included within the scope of computer-readable media.

[0050] The previous description of the disclosure is provided to enable any person skilled in the art to make or use the disclosure. Various modifications to the disclosure will be apparent to those skilled in the art, and the general principles defined herein may be applied to other variations without departing from the spirit or scope of the disclosure. Thus, the disclosure is not intended to be limited to the examples and designs described herein, but should be granted the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for a remote component sharing mechanism during front-end runtime based on JS entry, characterized in that: The method includes the processing of the construction phase and the processing of the running phase, in which: The processing in the construction phase includes each sub-application generating its own description file and entry file in the construction phase. The entry file includes the JS entry file and the CSS entry file. The HTML elements in the front-end application are compiled into JS code and mixed into the JS resources. The CSS resources in the front-end application are loaded through the CSS entry file. The processing flow of the operation phase includes: Step 1: Start the main application and sub-applications. The main application generates a global EventBus instance. Step 2: The main application loads the description file of the sub-application and obtains the sub-application name, resource address, and routing information data; Step 3: The main application starts loading the module, which includes: the main application dynamically generates a DIV tag, the main application loads and executes the JS entry file and CSS entry file of the sub-application, when the sub-application JS is executed, it checks whether there is a global EventBus instance, if it exists, it uses the EventBus instance, if not, it actively generates an EventBus instance and uses it as the global EventBus instance, the main application notifies the sub-application of the identification number of the DIV tag through the initialization event in the form of an event, and different sub-applications listen to different event names; Step 4: The sub-application listens to the initialization event, executes the rendering logic after receiving the ID notification sent by the main application, and mounts the HTML in the JS into the DIV tag corresponding to the ID, so that multiple instances of the same sub-application can be mounted on one page and remain independent; In the construction phase, the sub-application is packaged into static resources through the webpack packaging tool, and the JS entry file, CSS entry file, and description file are generated to complete the online deployment; Among them, in the process of generating entry files in the construction phase, the JS code is encapsulated by using the JS immediate execution function, and the dependent modules of the sub-application are used as parameters of the JS immediate execution function to generate a JS entry file, so that the JS of different sub-applications can only access the dependent modules of the sub-application, avoiding the mutual influence of the dependencies of various sub-applications in the main application.

2. The method of the front-end runtime remote component sharing mechanism based on JS entry according to claim 1 is characterized in that: The description file is used for the main application to access each sub-application during the running stage. By identifying the description file information, the address of the entry file of each sub-application is obtained. The description file contains data including the sub-application version number, sub-application name, resource address, and routing information.

3. The method of the front-end runtime remote component sharing mechanism based on JS entry according to claim 1 is characterized in that: The entry file is used to load the entry file of the sub-application and execute the entry file when the main application loads the sub-application, and mount the sub-application to the specified area of ​​the main application.

4. The method of the front-end runtime remote component sharing mechanism based on JS entry according to claim 1 is characterized in that: In the process of generating the entry file in the build phase, the CSS file of the sub-application is parsed by AST, the name of the sub-application is added to the CSS selector, a new AST is generated, and finally the AST is converted into a CSS entry file.

5. The method of the front-end runtime remote component sharing mechanism based on JS entry according to claim 1 is characterized in that: The ID of the DIV tag is a random number.

6. The method of the front-end runtime remote component sharing mechanism based on JS entry according to claim 1 is characterized in that: The method also includes: Step 5: When the main application page is switched and the sub-application is no longer needed, the main application starts the process of uninstalling the sub-application: on the one hand, the main application notifies the sub-application through an event to perform the uninstallation, and then after the sub-application receives the uninstallation event notification from the main application, it processes its own uninstallation logic and completes the uninstallation; on the other hand, the main application actively removes the sub-application CSS resources.