Web base rendering method and device, equipment and medium

By configuring the sub-application registry and the rendering method of the main application in a single-page application, the problems of high coupling between modules and slow response are solved, fast loading and rendering are achieved, and the user experience is improved.

CN118626170APending Publication Date: 2024-09-10DIGITAL LUZHOU BIG DATA TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410809672.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

In single-page applications, the coupling between functional modules is high, resulting in complex calls between modules, difficulty in updating, slow system response, loading of irrelevant files slows down the page loading speed, and reduces the user experience.

Method used

By configuring the sub-application registry, the main application determines the target sub-application based on routing changes, loads and renders it, and calls the uninstall life cycle hook to clean and uninstall according to user needs, avoiding the loading of irrelevant files and improving page loading speed.

Benefits of technology

Improved system response speed, improved user experience, and provided a better environment for subsequent loading through cleaning and uninstallation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626170A
    Figure CN118626170A
Patent Text Reader

Abstract

The invention discloses a web base rendering method and device, equipment and a medium, and the method comprises the steps: configuring a sub-application registry which at least comprises an entry address, a namespace and a route matching rule corresponding to each sub-application; when the route change is triggered, the main application determines a first target sub-application according to the sub-application registry; carrying out loading and rendering according to the information of the first target sub-application; when the user needs to replace the first target sub-application, the main application calls a preset uninstalling life cycle hook; and the main application cleans and unloads the first target sub-application. The invention belongs to the field of application loading rendering. According to the invention, the technical problems of slow system feedback and poor user experience can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of application loading and rendering, and in particular to a web base rendering method, device and medium. Background Art

[0002] Web (World Wide Web) refers to a huge information space formed by information resources from all over the world connected through the Internet. Web is an important part of the Internet and is an information system composed of many interconnected hypertexts. The development of Web has gone through many stages, from the initial static web pages to dynamic web pages, Web2.0, mobile Internet and responsive design, etc., and has continuously evolved and developed to provide users with richer and more convenient information and services. With the continuous expansion of the scale of Internet applications, Web applications have more and more functions, and the business relationships between functional modules are becoming more and more complex.

[0003] For SPA (single page application), various problems will follow and become more and more prominent. For example, the coupling between functional modules will become higher and higher, and the jumps and calls between modules will become more complicated, and unpredictable bugs will easily occur; it is difficult to update applications. Updating a small function requires repackaging and deploying the entire project, which is more difficult to manage for large web applications involving multiple project teams to develop together; the system response will become slow. For example, when loading a functional module, many irrelevant files and codes need to be loaded, which slows down the page loading speed and reduces the user experience. In view of this, this application proposes a web base rendering method to solve the technical problems of slow system feedback and poor user experience. Summary of the invention

[0004] The embodiments of the present application solve the technical problems of slow system feedback and poor user experience in the prior art by providing a web base rendering method, device equipment and medium, and achieve the technical effect of improving the system response speed.

[0005] In a first aspect, the present application provides a web base rendering method, a main application and several sub-applications, the method comprising:

[0006] Configure the sub-application registry, which at least includes the entry address, namespace, and routing matching rules corresponding to each sub-application;

[0007] When a routing change is triggered, the main application determines the first target sub-application based on the sub-application registration table;

[0008] Load and render according to the information of the first target sub-application;

[0009] When the user needs to replace the first target sub-application, the main application calls the preset uninstall lifecycle hook;

[0010] The main application cleans up and uninstalls the first target sub-application.

[0011] Further, loading and rendering are performed according to the information of the first target sub-application, including:

[0012] Parsing and loading the JavaScript module of the first target sub-application according to the information of the first target sub-application;

[0013] Create a target initialization function and return it to the main application;

[0014] Initialize based on the target initialization function and load the target HTML resource and target CSS resource;

[0015] Create and mount a document object model corresponding to the first target sub-application;

[0016] Executes the default mount lifecycle hook.

[0017] Further, the main application determines the first target sub-application according to the sub-application registration table, including:

[0018] The main application determines the first target sub-application according to the routing matching rule of the sub-application registration table.

[0019] Further, according to the information of the first target sub-application, parsing and loading the JavaScript module of the first target sub-application includes:

[0020] According to the information of the first target sub-application, obtaining the application package file of the first target sub-application;

[0021] Parse and load a JavaScript module of the application package file of the first target sub-application.

[0022] Furthermore, the sub-application registration table also includes:

[0023] Sub-application name, version number, team information, dependency information, compatibility information, license information, update log, configuration items, and performance indicators.

[0024] Further, uninstalling the first target sub-application includes:

[0025] Uninstall the DMO tree corresponding to the first target sub-application.

[0026] Furthermore, after cleaning and uninstalling the first target sub-application, the method further includes:

[0027] Parsing and loading the JavaScript module of the second target sub-application according to the information of the second target sub-application;

[0028] Create a target initialization function and return it to the main application;

[0029] Initialize based on the target initialization function and load the target HTML resource and target CSS resource;

[0030] Create and mount a document object model corresponding to the second target sub-application;

[0031] Executes the default mount lifecycle hook.

[0032] In a second aspect, the present application provides a web base rendering device, the device comprising:

[0033] A configuration module is used to configure a sub-application registry, which includes at least the entry address, namespace, and routing matching rules corresponding to each sub-application;

[0034] A target determination module, used for triggering a route change, when the main application determines the first target sub-application according to the sub-application registration table;

[0035] A loading and rendering module, used for loading and rendering according to information of the first target sub-application;

[0036] A calling module, used for the main application to call a preset uninstall lifecycle hook when the user has a need to replace the first target sub-application;

[0037] The cleaning and uninstalling module is used for the main application to clean up and uninstall the first target sub-application.

[0038] In a third aspect, the present application provides an electronic device, including:

[0039] processor;

[0040] a memory for storing processor-executable instructions;

[0041] Wherein, the processor is configured to execute to implement a web base rendering method provided in the first aspect.

[0042] In a fourth aspect, the present application provides a non-temporary computer-readable storage medium. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute a web base rendering method as provided in the first aspect.

[0043] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:

[0044] The present application provides a web base rendering method, including a main application and several sub-applications, the method including: configuring a sub-application registry, the sub-application registry including at least the entry address, namespace and route matching rules corresponding to each sub-application; when a route change is triggered, the main application determines the first target sub-application according to the sub-application registry; loads and renders according to the information of the first target sub-application; when the user has a need to replace the first target sub-application, the main application calls a preset uninstall lifecycle hook; the main application cleans up and uninstalls the first target sub-application. When the route change is triggered in the present application, the main application determines the first target sub-application according to the sub-application registry; loads and renders according to the information of the first target sub-application, which can avoid loading irrelevant files and codes, improve page loading speed, and enhance user experience. When the user has a need to replace the first target sub-application, the present application also provides a better environment for subsequent loading and rendering of subsequent sub-applications through cleaning and unloading. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0046] Figure 1 A schematic diagram of a process flow of a web base rendering method provided in this application;

[0047] Figure 2 A schematic diagram of the structure of a web base rendering device provided in this application;

[0048] Figure 3 A schematic diagram of the structure of the electronic device provided in this application. DETAILED DESCRIPTION

[0049] The embodiment of the present application solves the technical problems of slow system feedback and poor user experience in the prior art by providing a web base rendering method.

[0050] The technical solution of the embodiment of the present application is to solve the above technical problems, and the overall idea is as follows:

[0051] A web base rendering method, a main application and several sub-applications, the method comprising: configuring a sub-application registry, the sub-application registry at least including entry addresses, namespaces and route matching rules corresponding to each sub-application; when a route change is triggered, the main application determines a first target sub-application according to the sub-application registry; loads and renders according to information of the first target sub-application; when a user has a need to replace the first target sub-application, the main application calls a preset uninstall lifecycle hook; the main application cleans up and uninstalls the first target sub-application.

[0052] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0053] First of all, the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0054] This application provides Figure 1 A web base rendering method shown includes steps S11-S15, which also includes a main application and several sub-applications.

[0055] Step S11, configure a sub-application registry, the sub-application registry at least including the entry address, namespace and routing matching rules corresponding to each sub-application.

[0056] Step S12: When a routing change is triggered, the main application determines the first target sub-application according to the sub-application registration table.

[0057] Step S13: loading and rendering according to the information of the first target sub-application.

[0058] Step S14: When the user needs to replace the first target sub-application, the main application calls a preset uninstall lifecycle hook.

[0059] Step S15: the main application cleans up and uninstalls the first target sub-application.

[0060] Regarding step S11, a sub-application registry is configured, and the sub-application registry includes at least the entry address, namespace and routing matching rules corresponding to each sub-application.

[0061] A web base rendering method provided in the present application includes a main application and several sub-applications. The main application is an application with a modular structure, and the main application can accept and integrate multiple sub-applications.

[0062] Configuring the sub-application registry refers to the process of registering and configuring each sub-application in the main application. The main application, as a container or carrier platform, can dynamically load, start and manage each sub-application. Sub-applications can be independently developed and deployed modules. Different sub-applications can provide different functions, services or interfaces. The functions of each sub-application can be set according to actual needs. By accepting multiple sub-applications, the main application can meet various customization, scalability and flexibility requirements.

[0063] The sub-application registry includes at least the entry address, namespace, and routing matching rules corresponding to each sub-application. The entry address refers to the access entry of the sub-application, that is, the address when the sub-application is loaded and started. The namespace refers to the namespace of the sub-application, which is used to uniquely identify and distinguish each sub-application in the main application. The routing matching rule refers to the routing rule that defines the sub-application, that is, the rule of how the main application forwards the request to the corresponding sub-application when the user accesses a specific URL.

[0064] In addition, the sub-application registry can also include: sub-application name, version number, team information, dependency information, compatibility information, license information, update log, configuration items, and performance indicators.

[0065] Regarding step S12, when a routing change is triggered, the main application determines the first target sub-application according to the sub-application registration table.

[0066] Specifically, the main application determines the first target sub-application and the information corresponding to the first target sub-application according to the routing matching rule in the sub-application registration table.

[0067] When a user navigates to a target route in the main application, for example, by clicking a link or performing an operation, the main application will search for the route matching rules in the sub-application registry based on the current route changes, and determine the first target sub-application corresponding to the route and the information corresponding to the first target sub-application based on the route matching rules. The information corresponding to each sub-application includes at least the name, path, and loading method of each sub-application.

[0068] Regarding step S13, loading and rendering are performed according to the information of the first target sub-application.

[0069] Specifically, after determining the first target sub-application and the information corresponding to the first target sub-application, the application package file of the first target sub-application can be obtained according to the information of the first target sub-application, and the application package file of the first target sub-application includes a JavaScript module. The JavaScript module of the first target sub-application can be parsed and loaded.

[0070] Specifically, the main application obtains the application package file of the sub-application from a predefined location or through a network request. This application package file can be a packaged JavaScript file that contains the code, style, and resources of the sub-application. The main application can parse the obtained application package file. After the application package file is parsed, the main application will load the sub-application according to the JavaScript module of the first target sub-application.

[0071] Create a target initialization function and return it to the main application, including:

[0072] After parsing and loading the JavaScript module of the sub-application, the main application executes the JavaScript code in the JavaScript module, creates and returns a target initialization function (bootstrap) function for the main application to call.

[0073] During the execution of JavaScript code, the sub-application can initialize its own running state, register components, load data, etc. The purpose of creating and returning the target initialization function (bootstrap) is to establish a communication bridge between the sub-application and the main application. By returning the bootstrap function, the sub-application exposes interfaces or methods to the main application, so that the main application can call the interface to control the behavior of the sub-application and obtain the status or data of the sub-application, thereby realizing modular combination and collaborative work in the micro-frontend architecture.

[0074] Initialize based on the target initialization function and load the target HTML resources and target CSS resources, including:

[0075] In the process of initializing the first target sub-application, the target HTML resource and the target CSS resource are loaded. The target HTML resource and the target CSS resource are two main types of files that constitute a web page. HTML is a markup language used to define the structure and content of a web page, and CSS is a style sheet language used to control the appearance and style of a web page. In the process of initializing (bootstrap) the sub-application, the HTML resource and the CSS resource are loaded to ensure that the sub-application can be displayed and run normally in the main application.

[0076] Create and mount the document object model corresponding to the first target sub-application, including:

[0077] During the initialization (bootstrap) process, a virtual DOM (document object model) corresponding to the first target sub-application of the application can also be created and mounted in a specified container. By mounting the virtual DOM, the sub-application can display its own UI in a specific area of ​​the main application, realizing integration and display in the main application.

[0078] Executes the default mount lifecycle hook.

[0079] After executing the above steps, it means that the rendering is completed, and the preset mount life hook (that is, the mount life cycle hook) can be executed. After the page is loaded and rendered, the sub-application is rendered into the DOM, and the preset mount life hook is triggered in the process.

[0080] Regarding step S14, when the user has a need to replace the first target sub-application, the main application calls a preset uninstall lifecycle hook.

[0081] When the user needs to replace the first target sub-application, in other words, when the user navigates to another route, causing the first sub-application to be replaced, the main application calls the preset uninstall lifecycle hook (that is, the unload lifecycle hook) to notify the first sub-application to prepare for uninstallation.

[0082] Regarding step S15, the main application cleans up and uninstalls the first target sub-application.

[0083] The main application cleans up first. The specific cleanup content can be set in advance, for example, releasing event listeners, clearing internal states, subscribing to events, timers, or network requests, etc.

[0084] Then, the DMO tree corresponding to the first target sub-application is unloaded. Unloading the DOM tree of the first target sub-application means removing all elements rendered by the sub-application from the DOM. This ensures that no unused elements remain on the page and makes room for the next sub-application to be loaded and rendered.

[0085] After cleaning and uninstalling the first target sub-application, the method further includes: parsing and loading the JavaScript module of the second target sub-application according to the information of the second target sub-application; creating a target initialization function and returning the target initialization function to the main application; initializing based on the target initialization function and loading the target HTML resource and the target CSS resource; creating and mounting the document object model corresponding to the second target sub-application; and executing the preset mounting life hook. This is similar to step S13, and can refer to step S13 for details.

[0086] In summary, the present application provides a web base rendering method, including a main application and several sub-applications, the method including: configuring a sub-application registry, the sub-application registry at least including the entry address, namespace and route matching rules corresponding to each sub-application; when a route change is triggered, the main application determines the first target sub-application according to the sub-application registry; loads and renders according to the information of the first target sub-application; when the user has a need to replace the first target sub-application, the main application calls a preset uninstall lifecycle hook; the main application cleans up and uninstalls the first target sub-application. The present application can avoid loading irrelevant files and codes, improve page loading speed, and enhance user experience by, when the route change is triggered, the main application determines the first target sub-application according to the sub-application registry; loads and renders according to the information of the first target sub-application. When the user has a need to replace the first target sub-application, the present application also provides a better environment for subsequent loading and rendering of subsequent sub-applications through cleaning and unloading.

[0087] This application provides Figure 2 A web base rendering device is shown, comprising:

[0088] Configuration module 21, used to configure a sub-application registry, the sub-application registry at least including the entry address, namespace and routing matching rules corresponding to each sub-application;

[0089] A target determination module 22, used for, when a route change is triggered, the main application determines a first target sub-application according to a sub-application registration table;

[0090] A loading and rendering module 23, used for loading and rendering according to information of the first target sub-application;

[0091] A calling module 24, configured to cause the main application to call a preset uninstall lifecycle hook when the user has a need to replace the first target sub-application;

[0092] The cleaning and uninstalling module 25 is used for the main application to clean up and uninstall the first target sub-application.

[0093] Based on the same inventive concept, the present application also provides Figure 3 An electronic device as shown includes:

[0094] Processor 31;

[0095] A memory 32 for storing instructions executable by the processor 31;

[0096] The processor 31 is configured to execute to implement a web base rendering method as provided above.

[0097] Based on the same inventive concept, the present application also provides a non-temporary computer-readable storage medium. When the instructions in the storage medium are executed by the processor 31 of the electronic device, the electronic device can execute a web base rendering method as provided above.

[0098] Since the electronic device introduced in this embodiment is an electronic device used to implement the information processing method in the embodiment of the present application, based on the information processing method introduced in the embodiment of the present application, a person skilled in the art can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the electronic device used by the information processing method in the embodiment of the present application, it belongs to the scope of protection of this application.

[0099] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0100] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0101] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0102] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0103] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0104] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A web base rendering method, characterized in that: A main application and several sub-applications, the method comprising: Configure a sub-application registry, wherein the sub-application registry includes at least an entry address, a namespace, and a routing matching rule corresponding to each sub-application; When a routing change is triggered, the main application determines a first target sub-application according to the sub-application registration table; Loading and rendering according to the information of the first target sub-application; When the user has a need to replace the first target sub-application, the main application calls a preset uninstall lifecycle hook; The main application cleans up and uninstalls the first target sub-application.

2. A web base rendering method according to claim 1, characterized in that: The loading and rendering according to the information of the first target sub-application includes: Parsing and loading the JavaScript module of the first target sub-application according to the information of the first target sub-application; Creating a target initialization function, and returning the target initialization function to the main application; Initialize based on the target initialization function, and load the target HTML resource and the target CSS resource; Creating and mounting a document object model corresponding to the first target sub-application; Executes the default mount lifecycle hook.

3. A web base rendering method according to claim 1, characterized in that: The main application determines the first target sub-application according to the sub-application registration table, including: The main application determines the first target sub-application according to the routing matching rule of the sub-application registration table.

4. A web base rendering method as claimed in claim 2, characterized in that: The step of parsing and loading the JavaScript module of the first target sub-application according to the information of the first target sub-application includes: Acquire an application package file of the first target sub-application according to the information of the first target sub-application; Parse and load the JavaScript module of the application package file of the first target sub-application.

5. A web base rendering method according to claim 1, characterized in that: The sub-application registration table further includes: Sub-application name, version number, team information, dependency information, compatibility information, license information, update log, configuration items, and performance indicators.

6. A web base rendering method according to claim 1, characterized in that: Uninstalling the first target sub-application includes: Uninstall the DMO tree corresponding to the first target sub-application.

7. A web base rendering method according to claim 1, characterized in that: After cleaning and uninstalling the first target sub-application, the method further includes: Parsing and loading the JavaScript module of the second target sub-application according to the information of the second target sub-application; Creating a target initialization function, and returning the target initialization function to the main application; Initialize based on the target initialization function, and load the target HTML resource and the target CSS resource; Creating and mounting a document object model corresponding to the second target sub-application; Executes the default mount lifecycle hook.

8. A web base rendering device, characterized in that: The device comprises: A configuration module, used to configure a sub-application registry, wherein the sub-application registry includes at least an entry address, a namespace, and a routing matching rule corresponding to each sub-application; A target determination module, configured to, when a route change is triggered, determine the first target sub-application according to the sub-application registration table by the main application; A loading and rendering module, used for loading and rendering according to the information of the first target sub-application; A calling module, configured to cause the main application to call a preset uninstall lifecycle hook when a user has a need to replace the first target sub-application; The cleaning and uninstalling module is used for the main application to clean up and uninstall the first target sub-application.

9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; Wherein, the processor is configured to execute to implement a web base rendering method as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to implement a web base rendering method as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Front-end sub-application calling method and device, equipment and storage medium

    CN121523763A

  • A front-end sub-application calling method, device and equipment and storage medium

    CN121523763B