Applet page rendering method and device, electronic equipment and storage medium
By sharing rendering code and container resources in the shared storage space of the mini program, the logic layer and view layer can communicate directly, which solves the problems of high memory consumption and slow rendering speed of mini programs, and achieves faster page rendering and wider applicability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING BAIDU NETCOM SCI & TECH CO LTD
- Filing Date
- 2022-08-24
- Publication Date
- 2026-05-29
Smart Images

Figure CN115469866B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a method, apparatus, electronic device, storage medium, and computer program product for rendering pages of a mini-program. Background Technology
[0002] Mini-programs are applications that can be used without downloading or installation; users can open them by scanning QR codes, searching, or other methods. Currently, mini-programs are widely used due to their ease of use and small file size, making daily life more convenient. For example, users can use mini-programs to order food and shop. However, among related technologies, mini-programs consume a relatively large amount of memory resources. Summary of the Invention
[0003] This disclosure provides a method, apparatus, electronic device, storage medium, and computer program product for rendering pages of a mini-program.
[0004] According to one aspect of this disclosure, a method for rendering pages in a mini-program is provided. The mini-program includes a logic layer and a view layer. Resources shared between the logic layer and the view layer are deployed in a shared storage space of the mini-program. The method includes: the logic layer obtaining rendering code for rendering pages from the shared storage space; the logic layer executing the rendering code; the logic layer sending a rendering instruction to the view layer based on the rendering code; the view layer, in response to the rendering instruction, obtaining a container for rendering pages from the shared storage space; and the view layer rendering n target pages through the container, where n is a positive integer.
[0005] According to another aspect of this disclosure, a page rendering apparatus for a mini-program is provided. The mini-program includes a logic layer and a view layer, and resources shared between the logic layer and the view layer are deployed in the shared storage space of the mini-program. The apparatus includes: a first acquisition module for acquiring rendering code for rendering a page from the shared storage space; an execution module for executing the rendering code; a sending module for sending rendering instructions to the view layer based on the rendering code; a second acquisition module for acquiring a container for rendering a page from the shared storage space in response to the rendering instructions; and a rendering module for rendering n target pages through the container, where n is a positive integer.
[0006] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to execute a page rendering method of a mini-program.
[0007] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing the computer to execute a page rendering method for an applet.
[0008] According to another aspect of this disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, it implements the steps of a page rendering method for an app.
[0009] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0010] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0011] Figure 1 This is a flowchart illustrating the page rendering method of a mini-program according to the first embodiment of this disclosure;
[0012] Figure 2 This is a flowchart illustrating the page rendering method of a mini-program according to the second embodiment of this disclosure;
[0013] Figure 3 This is a flowchart illustrating a page rendering method for a mini-program according to a third embodiment of the present disclosure.
[0014] Figure 4 This is a flowchart illustrating the page rendering method of a mini-program according to the fourth embodiment of this disclosure;
[0015] Figure 5 This is a flowchart illustrating the page rendering method of a mini-program according to the fifth embodiment of this disclosure;
[0016] Figure 6 This is a schematic diagram of a page rendering method for a mini-program according to the sixth embodiment of this disclosure;
[0017] Figure 7 This is a schematic diagram of a mini-program in the page rendering method of a mini-program according to the seventh embodiment of this disclosure;
[0018] Figure 8 This is a block diagram of a page rendering apparatus for a mini-program according to a first embodiment of the present disclosure;
[0019] Figure 9 This is a block diagram of an electronic device used to implement the page rendering method of the applet in the embodiments of this disclosure. Detailed Implementation
[0020] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0021] Mini-programs are applications that can be used without downloading or installation. Users can open them by scanning QR codes, searching, or other methods. They are widely used due to their ease of use, small footprint, and low development costs. Currently, most mini-programs adopt a dual-thread structure, separating the logic layer and the view layer, which run on different threads.
[0022] Mini-program page rendering typically includes WebView (web page view) rendering and NAview (native view) rendering (which can be referred to as native rendering). Currently, when the view layer renders multiple pages, it needs to create a container for each page and create a thread for each page based on its own virtual machine.
[0023] Figure 1 This is a flowchart illustrating the page rendering method of a mini-program according to the first embodiment of this disclosure.
[0024] like Figure 1 As shown, the page rendering method for a mini-program according to the first embodiment of this disclosure includes:
[0025] S101, the logic layer retrieves the rendering code for rendering the page from the shared storage space.
[0026] In the embodiments of this disclosure, the mini-program includes a logic layer and a view layer, and resources shared between the logic layer and the view layer are deployed in the shared storage space of the mini-program. It should be noted that the mini-program has a shared storage space, in which resources shared between the logic layer and the view layer are deployed; that is, the logic layer and the view layer can share resources through the shared storage space. No excessive limitations are placed on the storage structure, storage location, or shared resources of the shared storage space. For example, the shared storage space may be deployed in the logic layer and / or the view layer.
[0027] It should be noted that both the logic layer and the view layer have operation permissions for the shared storage space. These operation permissions include at least obtaining shared resources from the shared storage space. In one embodiment, the operation permission also includes storing shared resources in the shared storage space.
[0028] In the embodiments of this disclosure, rendering code for rendering pages is deployed in the shared storage space; that is, the shared resources include rendering code, and the logic layer obtains the rendering code for rendering pages from the shared storage space. It should be noted that the rendering code is not subject to excessive limitations; for example, the rendering code includes native rendering code for rendering native pages.
[0029] In one implementation, logic code and developer code are also deployed in the shared storage space.
[0030] It should be noted that there are no strict restrictions on the code. For example, the code can be written in programming languages such as C, C++, and JS (JavaScript, an interpreted or just-in-time programming language).
[0031] S102, the logic layer executes the rendering code.
[0032] S103, the logic layer sends rendering instructions to the view layer based on the rendering code.
[0033] Understandably, since the rendering code defines the relevant content for sending rendering commands, the logic layer can send rendering commands to the view layer based on the rendering code. Therefore, the logic layer can directly send rendering commands to the view layer to drive the view layer to perform page rendering. Compared to the communication method in related technologies where the logic layer sends data to the view layer, this helps reduce the number of communication sessions and the communication time between the logic layer and the view layer, thereby improving the page rendering speed of the mini-program.
[0034] It should be noted that there are no strict restrictions on rendering instructions. For example, rendering instructions can be JSON (JavaScriptObject Notation).
[0035] In one implementation, the logic layer sends rendering instructions to the view layer based on the rendering code. This may include the logic layer obtaining the identifiers of n target pages to be rendered, generating rendering instructions based on the rendering code and the identifiers of the n target pages, and then sending the rendering instructions to the view layer. Here, n is a positive integer. It should be noted that n is not subject to many limitations; for example, n can be 1, 5, etc.
[0036] It should be noted that each target page has a unique identifier. There are no strict limitations on the target page identifier; for example, it may include, but is not limited to, the target page's name and URL (Uniform Resource Locator).
[0037] In one implementation, the logic layer can generate a rendering instruction based on the rendering code and the identifiers of n target pages. Thus, one rendering instruction can correspond to the identifier of at least one target page, helping to reduce the number of instructions.
[0038] In one implementation, the rendering instruction carries identifiers for n target pages.
[0039] S104, the view layer responds to the rendering instruction by obtaining a container from the shared storage space for rendering the page.
[0040] In the embodiments of this disclosure, a container for rendering pages is deployed in the shared storage space; that is, the shared resources include the container. The view layer, in response to rendering instructions, retrieves the container for rendering pages from the shared storage space. It should be noted that the container is not overly limited; for example, the container may include JSContext (a JS container).
[0041] In one implementation, the mini-program adopts a single-container structure, meaning that only one container is deployed within the shared storage space. It is understood that this container is used at least for rendering the page. Therefore, this method only requires deploying one container in the shared storage space, and the logic layer and view layer can share the container through this shared storage space, significantly reducing the number of containers and helping to save memory resources used by the mini-program.
[0042] For example, an electronic device hosts a mini-program. The mini-program uses a single-container structure, significantly reducing the number of containers and saving memory resources on the host device. This, in turn, saves memory resources on the electronic device, improving the mini-program's applicability and facilitating its expansion to in-vehicle terminals, smart home appliances, and other electronic devices. It should be noted that the term "electronic device" is not overly limited; for example, it includes IoT (Internet of Things) devices.
[0043] S105, the view layer renders n target pages through a container, where n is a positive integer.
[0044] For example, the target pages include target pages 1 to 3. The view layer obtains container A from the shared storage space for rendering the pages. The view layer renders target page 1 through container A, renders target page 2 through container A, and renders target page 3 through container A.
[0045] In summary, according to the page rendering method of the mini-program according to the embodiments of this disclosure, the shared storage space of the mini-program deploys resources shared between the logic layer and the view layer. The logic layer obtains rendering code for rendering the page from the shared storage space, executes the rendering code, and sends rendering instructions to the view layer based on the rendering code. The view layer responds to the rendering instructions by obtaining a container for rendering the page from the shared storage space, and renders n target pages through the container. Thus, the logic layer and the view layer can share resources through the shared storage space. The shared resources include at least rendering code and containers, and at least one target page can be rendered through a single container, greatly reducing the number of containers, helping to save memory resources occupied by the mini-program, and improving the applicability of the mini-program.
[0046] Figure 2 This is a flowchart illustrating the page rendering method of a mini-program according to the second embodiment of this disclosure.
[0047] like Figure 2 As shown, the page rendering method for a mini-program according to the second embodiment of this disclosure includes:
[0048] S201, the logic layer retrieves the rendering code used to render the page from the shared storage space.
[0049] S202, the logic layer executes the rendering code.
[0050] S203, the logic layer sends rendering instructions to the view layer based on the rendering code.
[0051] S204, the view layer responds to the rendering instruction by obtaining a container from the shared storage space for rendering the page.
[0052] The relevant content of steps S201-S204 can be found in the above embodiments, and will not be repeated here.
[0053] S205, the view layer obtains the rendering resources corresponding to the i-th target page from the container, where 1≤i≤n and i is a positive integer.
[0054] It should be noted that there are no major restrictions on rendering resources. For example, rendering resources include, but are not limited to, JS files, CSS (Cascading Style Sheets) files, fonts, images, page attribute values, etc.
[0055] In the embodiments of this disclosure, the container stores rendering resources corresponding to n target pages. It is understood that different target pages can correspond to different rendering resources. For example, the target pages include target pages 1 to 3. The view layer obtains a container A for rendering the pages from the shared storage space. Container A stores the rendering resources corresponding to target page 1, target page 2, and target page 3.
[0056] In one implementation, the view layer retrieves the rendering resource corresponding to the i-th target page from the container. This includes the view layer retrieving the rendering resource corresponding to the i-th target page from the container based on the identifier of the i-th target page. For example, a mapping relationship or mapping table between the identifier of the target page and the rendering resource can be established in the container. After obtaining the identifier of the i-th target page, the view layer queries the above mapping relationship or mapping table and determines the retrieved rendering resource as the rendering resource corresponding to the i-th target page.
[0057] In one implementation, the view layer retrieves rendering resources corresponding to n target pages from the mini-program's storage space, and stores these rendering resources in separate containers. It should be noted that the mini-program's storage space contains rendering resources corresponding to n target pages. Therefore, this method allows the rendering resources for at least one target page to be stored in a single container, significantly reducing the number of containers and helping to conserve the mini-program's memory resources.
[0058] In one implementation, the view layer stores the rendering resources corresponding to the n target pages in containers, including storing the rendering resource corresponding to the i-th target page in the i-th storage space of the container. It should be noted that the container includes n storage spaces, each corresponding one-to-one with one of the n target pages, and the i-th storage space is used to store the rendering resource corresponding to the i-th target page.
[0059] For example, the target pages include target pages 1 to 3. The view layer obtains container A for rendering the pages from the shared storage space. The view layer obtains the rendering resources corresponding to target pages 1 to 3 from the storage space of the mini program. The rendering resources corresponding to target page 1 are stored in the first storage space of container A, the rendering resources corresponding to target page 2 are stored in the second storage space of container A, and the rendering resources corresponding to target page 3 are stored in the third storage space of container A.
[0060] In one implementation, after the view layer stores the rendering resources corresponding to the n target pages in containers, it further includes identifying overlapping rendering resources among the rendering resources corresponding to the m first pages among the n target pages, where 2 ≤ m ≤ n, and m is a positive integer. The view layer retains the overlapping rendering resource corresponding to any one of the first pages in the container. Therefore, this method can retain only the overlapping rendering resource corresponding to any one of the first pages in the container when there are overlapping rendering resources among the m first pages, i.e., only one set of overlapping rendering resources in the container. This helps save the memory resources occupied by the rendering resources in the container, and thus saves the memory resources occupied by the mini-program.
[0061] It is understandable that the n target pages include m first pages, where the m first pages are some or all of the n target pages. Overlapping rendering resources refer to the overlapping portions of the rendering resources corresponding to the m first pages. The view layer retains the overlapping rendering resources corresponding to any one of the first pages in the container, including cases where the view layer deletes the overlapping rendering resources corresponding to all other first pages in the container.
[0062] For example, the target pages include target pages 1 to 3. The view layer obtains container A for rendering the pages from the shared storage space. The view layer stores the rendering resources corresponding to target pages 1 to 3 in container A respectively. The view layer can identify that there are overlapping rendering resources between target pages 1 and 2, and thus determine target pages 1 and 2 as the first page.
[0063] In some embodiments, the view layer retains the overlapping rendering resources corresponding to the target page 1 in container A, and deletes the overlapping rendering resources corresponding to the target page 2 in container A.
[0064] In some embodiments, the view layer retains the overlapping rendering resources corresponding to the target page 2 in container A, and deletes the overlapping rendering resources corresponding to the target page 1 in container A.
[0065] In one implementation, the view layer stores the rendering resources corresponding to the n target pages in containers. This includes the view layer identifying overlapping rendering resources among the rendering resources corresponding to the m first pages out of the n target pages, and identifying the differential rendering resources (excluding the overlapping resources) within the rendering resources corresponding to each first page, where 2 ≤ m ≤ n, and m is a positive integer. The view layer stores the overlapping and differential rendering resources in containers respectively. Therefore, this method can save memory resources occupied by the containers when there are overlapping rendering resources among the m first pages by storing one set of overlapping rendering resources and one set of differential rendering resources for each set of m first pages in a container. This helps to save memory resources occupied by the rendering resources, thereby saving memory resources occupied by the mini-program.
[0066] In one implementation, the view layer stores concurrent rendering resources and differential rendering resources in containers respectively. Specifically, the view layer stores concurrent rendering resources in the container's concurrent storage space and stores the differential rendering resources corresponding to the j-th first page in the container's j-th differential storage space. Here, 1 ≤ j ≤ m, and j is a positive integer. It should be noted that the container includes a concurrent storage space and m differential storage spaces. The concurrent storage space stores concurrent rendering resources, and the m differential storage spaces correspond one-to-one with the m first pages. The j-th differential storage space stores the differential rendering resources corresponding to the j-th first page.
[0067] For example, the target pages include target pages 1 to 3. The view layer obtains container A for rendering the page from the shared storage space. The view layer identifies that there are overlapping rendering resources between target pages 1 and 2, so target pages 1 and 2 can be determined as the first page. The view layer identifies the different rendering resources in the rendering resources corresponding to target pages 1 and 2, excluding the overlapping rendering resources.
[0068] The view layer stores the overlapping rendering resources in the overlapping storage space of container A, stores the differential rendering resources corresponding to target page 1 in the first differential storage space of container A, and stores the differential rendering resources corresponding to target page 2 in the second differential storage space of container A.
[0069] S206, the view layer renders the i-th target page using the container and the rendering resources corresponding to the i-th target page.
[0070] For example, the target pages include target pages 1 to 3. The view layer obtains container A from the shared storage space for rendering the pages. The view layer obtains the rendering resources corresponding to target pages 1 to 3 from container A. Target page 1 is rendered using container A and the rendering resources corresponding to target page 1. Target page 2 is rendered using container A and the rendering resources corresponding to target page 2. Target page 3 is rendered using container A and the rendering resources corresponding to target page 3.
[0071] In summary, according to the page rendering method of the mini-program according to the embodiments of this disclosure, the view layer obtains the rendering resource corresponding to the i-th target page from the container, and the view layer renders the i-th target page using the container and the rendering resource corresponding to the i-th target page. Therefore, this method can obtain at least one rendering resource corresponding to a target page from the container, and render each target page using the container and the rendering resource corresponding to each target page.
[0072] Figure 3 This is a flowchart illustrating the page rendering method of a mini-program according to the third embodiment of this disclosure.
[0073] like Figure 3As shown, the page rendering method for a mini-program according to the third embodiment of this disclosure includes:
[0074] S301, the view layer obtains the set events on the target page.
[0075] It should be noted that there are no strict limitations on the events that can be set. For example, events can include, but are not limited to, click events, swipe events, scroll events, refresh events, and text box events.
[0076] In one implementation, the view layer acquires set events on the target page, including the view layer listening for events on the target page.
[0077] It should be noted that there are no strict restrictions on the listening method. For example, the view layer can deploy listening code, and the view layer can listen for events on the target page. This includes the view layer executing the listening code, which then listens for events on the target page. It should also be noted that there are no strict restrictions on the listening code itself.
[0078] In one implementation, the view layer deploys a rendering engine, and the view layer obtains set events on the target page, including obtaining set events on the target page through the rendering engine. It should be noted that the rendering engine is not overly limited; for example, the rendering engine may include a native rendering engine.
[0079] S302, the view layer sends the setting event to the logic layer.
[0080] In one implementation, the view layer deploys a rendering engine, and the view layer sends setting events to the logic layer, including the view layer sending setting events to the logic layer through the rendering engine. Therefore, in this method, the rendering engine can directly send setting events to the logic layer. Compared to related technologies where the rendering engine sends setting events to the view layer, and then the view layer sends setting events to the logic layer, this helps reduce the number of communication sessions and communication time between the logic layer and the view layer, thereby improving the page rendering speed of the mini-program.
[0081] S303, the logic layer retrieves the processing code for the set event from the shared storage space.
[0082] S304, the logic layer executes the processing code and, based on the processing code, handles the set events.
[0083] In the embodiments of this disclosure, the shared storage space also deploys processing code for set events; that is, the shared resources include processing code for set events, and the logic layer obtains the processing code for set events from the shared storage space. It should be noted that the processing code is not subject to excessive limitations, and different set events may correspond to different processing codes.
[0084] In one implementation, a mapping relationship or mapping table between setting events and processing codes can be established in the shared storage space. After the logic layer obtains the setting event, it queries the above mapping relationship or mapping table and determines the processing code found as the processing code for the setting event.
[0085] In one implementation, the logic layer generates rendering instructions corresponding to the set events based on rendering code and set events, and sends the rendering instructions to the view layer. The view layer responds to the rendering instructions and renders the target page. Therefore, in this method, the logic layer can generate rendering instructions based on rendering code and set events, and directly send the rendering instructions to the view layer to drive the view layer to render the target page. Compared to the communication method in related technologies where the logic layer sends data to the view layer, this helps reduce the number of communication sessions and the communication time between the logic layer and the view layer, thereby improving the page rendering speed of the mini-program.
[0086] In summary, according to the page rendering method of the mini-program according to the embodiments of this disclosure, the view layer obtains a set event on the target page, sends the set event to the logic layer, the logic layer obtains the processing code of the set event from the shared storage space, executes the processing code, and processes the set event based on the processing code. Thus, the logic layer and the view layer can share resources through the shared storage space, and the shared resources also include the processing code of the set event. The logic layer can obtain the processing code of the set event from the shared storage space and process the set event based on the processing code.
[0087] Figure 4 This is a flowchart illustrating the page rendering method of a mini-program according to the fourth embodiment of this disclosure.
[0088] like Figure 4 As shown, the page rendering method for a mini-program according to the fourth embodiment of this disclosure includes:
[0089] S401, the logic layer retrieves the rendering code used to render the page from the shared storage space.
[0090] S402, the logic layer executes the rendering code.
[0091] The details of steps S401-S402 can be found in the above embodiments and will not be repeated here.
[0092] S403, the logic layer sends rendering instructions to the rendering engine based on the rendering code.
[0093] In embodiments of this disclosure, a rendering engine is deployed in the view layer.
[0094] For details regarding step S403, please refer to step S103; they will not be repeated here.
[0095] In one implementation, before sending rendering instructions to the view layer, the logic layer further obtains the rendering methods of n target pages and identifies that the rendering method of the n target pages is native rendering. Therefore, in this method, the logic layer can send rendering instructions to the view layer when the rendering method of all n target pages is native rendering.
[0096] S404, the rendering engine responds to rendering commands by retrieving containers from shared storage.
[0097] For details regarding step S404, please refer to step S104; they will not be repeated here.
[0098] S405, the rendering engine renders n target pages through a container.
[0099] For details regarding step S405, please refer to step S105; they will not be repeated here.
[0100] In summary, according to the page rendering method of the mini-program according to the embodiments of this disclosure, the logic layer sends rendering instructions to the rendering engine, and the rendering engine responds to the rendering instructions by obtaining containers from the shared storage space. The rendering engine then renders n target pages through the containers. Therefore, the logic layer can directly send rendering instructions to the rendering engine to drive the rendering engine to perform page rendering. Compared to the communication method in related technologies where the logic layer sends data to the view layer and the view layer sends rendering instructions to the rendering engine, this helps to reduce the number of communication sessions and the communication time between the logic layer and the view layer, thereby improving the page rendering speed of the mini-program.
[0101] Figure 5 This is a flowchart illustrating the page rendering method of a mini-program according to the fifth embodiment of this disclosure.
[0102] like Figure 5 As shown, the page rendering method for a mini-program according to the fifth embodiment of this disclosure includes:
[0103] S501, the logic layer retrieves the rendering code used to render the page from the shared storage space.
[0104] S502, the logic layer executes the rendering code.
[0105] In S503, the logic layer sends rendering instructions to the view layer based on the rendering code.
[0106] S504, the view layer responds to rendering instructions by obtaining a container from shared storage space for rendering the page.
[0107] The relevant content of steps S501-S504 can be found in the above embodiments, and will not be repeated here.
[0108] S505, the view layer obtains the virtual machine from the shared storage space.
[0109] In S506, the view layer creates threads for containers through a virtual machine.
[0110] In the embodiments of this disclosure, a virtual machine is deployed in the shared storage space; that is, the shared resources include the virtual machine. The view layer obtains the virtual machine from the shared storage space and uses the virtual machine to create threads for the container. It should be noted that the virtual machine is not limited in many ways; for example, the virtual machine may include JSVM (JavaScript Virtual Machine).
[0111] In one implementation, the mini-program adopts a single-container structure. This means that a container requires only one thread and one virtual machine; that is, when the mini-program adopts a single-threaded structure, it is also a single-container, single-virtual-machine structure. Therefore, this method only requires deploying one container and one virtual machine in the shared storage space. The logic layer and view layer can share the container, virtual machine, and thread, greatly reducing the number of containers, virtual machines, and threads, and helping to save memory and thread resources occupied by the mini-program.
[0112] S507, the view layer executes a thread, and renders n target pages through a container within the thread.
[0113] For example, such as Figure 6 As shown, the target pages include target pages 1 to 3. The view layer obtains container A and virtual machine B from the shared storage space for rendering the pages. It creates thread C for container A through virtual machine B, executes thread C, and renders target page 1 through container A in thread C, renders target page 2 through container A in thread C, and renders target page 3 through container A in thread C.
[0114] In summary, according to the page rendering method of the mini-program according to the embodiments of this disclosure, the view layer obtains a virtual machine from the shared storage space, creates a thread for the container through the virtual machine, executes the thread, and renders n target pages through the container within the thread. Thus, the logic layer and the view layer can share resources through the shared storage space. The shared resources also include the virtual machine; one virtual machine can create one thread for one container, and one thread and one container can render at least one target page, greatly reducing the number of containers, virtual machines, and threads, helping to save memory resources occupied by the mini-program and improving its applicability.
[0115] Based on any of the above embodiments, such as Figure 7As shown, the mini-program 700 includes a logic layer 701, a view layer 702, and a shared storage space 703. The shared storage space 703 contains resources shared between the logic layer 701 and the view layer 702, such as... Figure 7 As shown, the shared storage space 703 contains rendering code 1 for rendering pages, a container 2 for rendering pages, event handling code 3, and a virtual machine 4. The view layer 702 contains a rendering engine 5.
[0116] In one implementation, the logic layer 701 retrieves rendering code 1 from the shared storage space 703, executes rendering code 1, and sends rendering instructions to the rendering engine 5 based on rendering code 1. Correspondingly, the rendering engine 5 responds to the rendering instructions, retrieves container 2 from the shared storage space 703, and renders n target pages through container 2.
[0117] In one implementation, the rendering engine 5 obtains a setting event on the target page and sends the setting event to the logic layer 701. The logic layer 701 obtains the processing code 3 of the setting event from the shared storage space 703, executes the processing code 3 of the setting event, and processes the setting event based on the processing code 3 of the setting event.
[0118] In one implementation, the logic layer 701 generates a rendering instruction for the setting event based on the rendering code 1 and the setting event, and sends the rendering instruction to the rendering engine 5. The rendering engine 5 responds to the rendering instruction and renders the target page.
[0119] In one implementation, the rendering engine 5 obtains the virtual machine 4 from the shared storage space 703, creates a thread for the container 2 through the virtual machine 4, executes the thread, and renders n target pages through the container 2 in the thread.
[0120] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0121] According to embodiments of this disclosure, this disclosure also provides a page rendering apparatus for a mini-program, used to implement the page rendering method for the mini-program described above.
[0122] Figure 8 This is a block diagram of a page rendering apparatus for a mini-program according to a first embodiment of the present disclosure. The mini-program includes a logic layer and a view layer, and resources shared between the logic layer and the view layer are deployed in the shared storage space of the mini-program.
[0123] like Figure 8As shown, the page rendering device 800 for a mini-program in this embodiment includes: a first acquisition module 801, an execution module 802, a sending module 803, a second acquisition module 804, and a rendering module 805.
[0124] The first acquisition module 801 is used to acquire rendering code for rendering the page from the shared storage space;
[0125] Execution module 802 is used to execute the rendering code;
[0126] The sending module 803 is used to send rendering instructions to the view layer based on the rendering code;
[0127] The second acquisition module 804 is used to acquire a container for rendering the page from the shared storage space in response to the rendering instruction;
[0128] The rendering module 805 is used to render n target pages through the container, where n is a positive integer.
[0129] In one embodiment of this disclosure, the rendering module 805 is further configured to: obtain the rendering resource corresponding to the i-th target page from the container, where 1≤i≤n and i is a positive integer; and render the i-th target page using the container and the rendering resource corresponding to the i-th target page.
[0130] In one embodiment of this disclosure, the rendering module 805 is further configured to: obtain rendering resources corresponding to n target pages from the storage space of the mini-program; and store the rendering resources corresponding to the n target pages in the container respectively.
[0131] In one embodiment of this disclosure, after storing the rendering resources corresponding to the n target pages in the container, the rendering module 805 is further configured to: identify overlapping rendering resources among the rendering resources corresponding to the m first pages in the n target pages, where 2≤m≤n and m is a positive integer; and retain the overlapping rendering resources corresponding to any first page in the container.
[0132] In one embodiment of this disclosure, the rendering module 805 is further configured to: identify overlapping rendering resources among the rendering resources corresponding to m first pages out of n target pages, and identify differential rendering resources other than the overlapping rendering resources among the rendering resources corresponding to each first page, wherein 2≤m≤n, and m is a positive integer; and store the overlapping rendering resources and the differential rendering resources in the container respectively.
[0133] In one embodiment of this disclosure, the page rendering device 800 of the mini-program further includes: a processing module, the processing module being configured to: acquire a set event on the target page; send the set event to the logic layer; acquire the processing code of the set event from the shared storage space; execute the processing code; and process the set event based on the processing code.
[0134] In one embodiment of this disclosure, the view layer is equipped with a rendering engine; the processing module is further configured to: send the set event to the logic layer through the rendering engine.
[0135] In one embodiment of this disclosure, the processing module is further configured to: generate a rendering instruction corresponding to the setting event based on the rendering code and the setting event, and send the rendering instruction to the view layer; the rendering module 805 is further configured to: render the target page in response to the rendering instruction.
[0136] In one embodiment of this disclosure, the rendering module 805 is further configured to: obtain a virtual machine from the shared storage space; create a thread for the container through the virtual machine; execute the thread, and render n target pages through the container in the thread.
[0137] In one embodiment of this disclosure, the view layer is equipped with a rendering engine; the sending module 803 is further configured to: send the rendering instructions to the rendering engine.
[0138] In one embodiment of this disclosure, the rendering engine responds to the rendering instruction by retrieving the container from the shared storage space; the rendering engine then renders the n target pages using the container.
[0139] In one embodiment of this disclosure, before sending the rendering instruction to the view layer, the sending module 803 is further configured to: obtain the rendering methods of n target pages and identify the rendering methods of the n target pages as native rendering.
[0140] In summary, the page rendering apparatus for a mini-program according to this embodiment deploys resources shared between the logic layer and the view layer in the shared storage space of the mini-program. The logic layer obtains rendering code for rendering the page from the shared storage space, executes the rendering code, and sends rendering instructions to the view layer based on the rendering code. In response to the rendering instructions, the view layer obtains a container for rendering the page from the shared storage space, and renders n target pages using the container. Therefore, the logic layer and the view layer can share resources through the shared storage space. The shared resources include at least rendering code and containers, and at least one target page can be rendered using a single container, greatly reducing the number of containers, helping to save memory resources occupied by the mini-program, and improving the applicability of the mini-program.
[0141] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0142] Figure 9 A schematic block diagram of an example electronic device 900 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0143] like Figure 9 As shown, the electronic device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded into a random access memory (RAM) 903 from a storage unit 908. The RAM 903 may also store various programs and data required for the operation of the electronic device 900. The computing unit 901, ROM 902, and RAM 903 are interconnected via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0144] Multiple components in electronic device 900 are connected to I / O interface 905, including: input unit 906, such as keyboard, mouse, etc.; output unit 907, such as various types of displays, speakers, etc.; storage unit 908, such as disk, optical disk, etc.; and communication unit 909, such as network card, modem, wireless transceiver, etc. Communication unit 909 allows electronic device 900 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0145] Computing unit 901 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Computing unit 901 performs the various methods and processes described above, such as... Figures 1 to 7 The page rendering method for the aforementioned applet. For example, in some embodiments, the page rendering method for the applet may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 908. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 900 via ROM 902 and / or communication unit 909. When the computer program is loaded into RAM 903 and executed by computing unit 901, one or more steps of the page rendering method for the applet described above may be performed. Alternatively, in other embodiments, computing unit 901 may be configured to execute the page rendering method for the applet by any other suitable means (e.g., by means of firmware).
[0146] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0147] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0148] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0149] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0150] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0151] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service system that addresses the shortcomings of traditional physical hosts and VPS (Virtual Private Server) services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.
[0152] According to embodiments of this disclosure, this disclosure also provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, it implements the steps of the page rendering method for the applet described in the above embodiments of this disclosure.
[0153] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0154] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A method for rendering a page in a mini-program, the mini-program comprising a logic layer and a view layer, wherein resources shared between the logic layer and the view layer are deployed in the shared storage space of the mini-program, the method comprising: The logic layer obtains the rendering code for rendering the page from the shared storage space; The logic layer executes the rendering code; The logic layer sends rendering instructions to the view layer based on the rendering code; In response to the rendering command, the view layer retrieves a container for rendering the page from the shared storage space, wherein only one container and one virtual machine are deployed in the shared storage space; The view layer creates threads for the container through the virtual machine, and renders n target pages through the threads and the container, where n is a positive integer; The rendering of the n target pages includes: The view layer obtains the rendering resources corresponding to the i-th target page from the container, where 1≤i≤n and i is a positive integer; The view layer renders the i-th target page using the container and the rendering resources corresponding to the i-th target page; The method further includes: The view layer obtains rendering resources corresponding to n target pages from the storage space of the mini-program; The view layer identifies overlapping rendering resources among the rendering resources corresponding to m first pages out of n target pages, and identifies different rendering resources other than the overlapping rendering resources among the rendering resources corresponding to each first page, where 2≤m≤n and m is a positive integer; The view layer stores the overlapping rendering resources and the differential rendering resources respectively in the container; The view layer retains the overlapping rendering resources corresponding to any first page in the container.
2. The method according to claim 1, wherein, The method further includes: The view layer obtains the set events on the target page; The view layer sends the set event to the logic layer; The logic layer obtains the processing code for the defined event from the shared storage space; The logic layer executes the processing code and processes the set event based on the processing code.
3. The method according to claim 2, wherein, The view layer is equipped with a rendering engine; The view layer sends the set event to the logic layer, including: The view layer sends the set events to the logic layer through the rendering engine.
4. The method according to claim 2, wherein, The method further includes: The logic layer generates a rendering instruction corresponding to the setting event based on the rendering code and the setting event, and sends the rendering instruction to the view layer; The view layer responds to the rendering instruction and renders the target page.
5. The method according to claim 1, wherein, The rendering of the n target pages includes: The view layer obtains the virtual machine from the shared storage space; The view layer creates threads for the container through the virtual machine; The view layer executes the thread, and within the thread, renders the n target pages through the container.
6. The method according to any one of claims 1-5, wherein, The view layer is equipped with a rendering engine; The logic layer sends the rendering instructions to the view layer, including: The logic layer sends the rendering instructions to the rendering engine.
7. The method according to claim 6, wherein, The view layer, in response to the rendering command, retrieves the container from the shared storage space, including: The rendering engine responds to the rendering command by retrieving the container from the shared storage space; The view layer renders the n target pages through the container, including: The rendering engine renders the n target pages through the container.
8. The method according to any one of claims 1-5, wherein, Before the logic layer sends the rendering instruction to the view layer, it also includes: The logic layer obtains the rendering methods of the n target pages and identifies the rendering methods of the n target pages as native rendering.
9. A page rendering apparatus for a mini-program, the mini-program including a logic layer and a view layer, wherein resources shared between the logic layer and the view layer are deployed in the shared storage space of the mini-program, the apparatus comprising: The first acquisition module is used to acquire rendering code for rendering the page from the shared storage space; An execution module is used to execute the rendering code; The sending module is used to send rendering instructions to the view layer based on the rendering code; The second acquisition module is used to acquire a container for rendering the page from the shared storage space in response to the rendering instruction, wherein only one container and one virtual machine are deployed in the shared storage space; A rendering module is used to create threads for the container through the virtual machine, and to render n target pages through the threads and the container, where n is a positive integer; The rendering module is further configured to: Obtain the rendering resource corresponding to the i-th target page from the container, where 1≤i≤n and i is a positive integer; The i-th target page is rendered using the container and the rendering resources corresponding to the i-th target page. The rendering module is further configured to: Obtain rendering resources corresponding to n target pages from the storage space of the mini-program; Identify overlapping rendering resources among the rendering resources corresponding to m first pages out of n target pages, and identify the different rendering resources other than the overlapping rendering resources among the rendering resources corresponding to each first page, where 2≤m≤n and m is a positive integer; The overlapping rendering resources and the differential rendering resources are stored in the container respectively; The overlapping rendering resources corresponding to any first page in the container are retained.
10. The apparatus according to claim 9, wherein, The device further includes: a processing module, the processing module being used for: Retrieve the set events on the target page; Send the specified event to the logic layer; Retrieve the processing code for the defined event from the shared storage space; The processing code is executed, and the set event is processed based on the processing code.
11. The apparatus according to claim 10, wherein, The view layer is equipped with a rendering engine; The processing module is further configured to: The rendering engine sends the set event to the logic layer.
12. The apparatus according to claim 10, wherein, The processing module is further configured to: generate a rendering instruction corresponding to the setting event based on the rendering code and the setting event, and send the rendering instruction to the view layer; The rendering module is further configured to: render the target page in response to the rendering instruction.
13. The apparatus according to claim 9, wherein, The rendering module is also used for: Obtain the virtual machine from the shared storage space; Threads are created for the container using the virtual machine; The thread is executed, and within the thread, the n target pages are rendered using the container.
14. The apparatus according to any one of claims 9-13, wherein, The view layer is equipped with a rendering engine; The sending module is further configured to: Send the rendering command to the rendering engine.
15. The apparatus according to claim 14, wherein, The rendering engine responds to the rendering command by retrieving the container from the shared storage space; The rendering engine renders the n target pages through the container.
16. The apparatus according to any one of claims 9-13, wherein, Before sending the rendering instruction to the view layer, the sending module is further configured to: Obtain the rendering methods of n target pages, and identify the rendering methods of the n target pages as native rendering.
17. An electronic device comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the page rendering method of the applet as described in any one of claims 1-8.
18. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to execute the page rendering method of the applet as described in any one of claims 1-8.
19. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the page rendering method of the applet as described in any one of claims 1-8.