Small program resource processing method and device, electronic equipment and storage medium
By constructing a page weight graph and resource tree, the download order of mini-program resource packages was optimized, which solved the problem of mini-program loading lag and improved resource processing efficiency and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2024-10-21
- Publication Date
- 2026-04-21
AI Technical Summary
Mini-program resource files are usually packaged in page order, which means that non-critical resource packages need to be downloaded first, increasing the initial loading time and reducing resource processing efficiency.
By identifying page navigation information in mini-programs, a page weight graph and resource tree are constructed to determine the download order of resource packages, which are then divided into packages, and loading information is generated to optimize the download order.
The loading order of mini-program resources has been optimized, reducing initial loading time and improving resource processing efficiency and user experience.
Smart Images

Figure CN121900829A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, specifically to a method, apparatus, electronic device, and storage medium for processing mini-program resources. Background Technology
[0002] The loading of a mini-program refers to the entire process from when a user launches the mini-program to when the mini-program is ready to accept user input and execute functions.
[0003] Currently, when loading a mini-program, the system first obtains the resource package configuration of the current mini-program based on the configuration information in the mini-program's source code; then, it downloads the mini-program's resource package, and then obtains the mini-program's resource files from the resource package through decryption and decompression. The resource files include the mini-program's page files, mini-program business code, etc.; finally, the mini-program loader reads the decrypted and decompressed resource files from the local machine and executes the mini-program's page loading logic and rendering.
[0004] However, the resource files of a mini program are usually packaged into resource bundles by page and in the natural order of the pages. Therefore, even if the resource files of some pages are not needed immediately at runtime, they may be packaged into resource bundles at the beginning of the list. This causes these non-critical resource bundles to have to be downloaded first during loading, which increases the initial loading time. When the resource files of a mini program are complex, loading may be slow, which reduces the efficiency of mini program resource processing. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, and storage medium for processing mini-program resources, which can improve the efficiency of mini-program resource processing.
[0006] This application provides a method for processing mini-program resources, including:
[0007] Obtain the source code file of the mini program;
[0008] Identify the mini-program page jump information in the mini-program source code file;
[0009] Based on the page jump information of the mini program, construct the page weight graph and page resource tree of the mini program page;
[0010] The download order of resource packages is determined based on the page weight map and the page resource tree;
[0011] The source code files of the mini-program are divided into packages to obtain page resource packages and package mapping relationship tables;
[0012] Based on the download order of the resource packages and the package mapping table, mini-program loading information is generated; the mini-program loading information indicates that the page resource packages of the mini-program are loaded in the configuration environment of the parent program.
[0013] This application embodiment also provides a mini-program resource processing device, including:
[0014] The file acquisition unit is used to acquire the source code files of the mini-program.
[0015] The file recognition unit is used to recognize the mini-program page jump information in the mini-program source code file;
[0016] The weight graph and resource tree construction unit is used to construct the page weight graph and page resource tree of the mini-program page based on the page jump information of the mini-program;
[0017] The resource package download order determination unit is used to determine the resource package download order based on the page weight graph and the page resource tree;
[0018] The sub-packaging unit is used to sub-package the source code file of the mini-program to obtain page resource packages and package mapping relationship tables;
[0019] The loading information generation unit is used to generate mini-program loading information according to the download order of the resource packages and the package mapping relationship table; the mini-program loading information indicates that the page resource package of the mini-program is loaded in the configuration environment of the parent program.
[0020] In some embodiments, the resource package download order determination unit is further configured to:
[0021] Based on the page weight graph, the download order of the mini-program pages is sorted to obtain the page download order;
[0022] For any of the aforementioned mini-program pages, the loading order of the page resources corresponding to the mini-program page is sorted according to the page resource tree to obtain the page resource loading order;
[0023] Based on the page download order and the page resource loading order, the resource package download order of the page resource package corresponding to the mini program page is obtained.
[0024] In some embodiments, the mini-program page includes a root node page and leaf node pages, and the resource package download order determination unit includes a page download order sorting subunit, which is specifically used for:
[0025] Based on the page weight graph, determine the first number of references between the root node page and the leaf node page, and determine the second number of references between the leaf node pages;
[0026] For any of the aforementioned mini-program pages, a first download weight of the mini-program page is calculated based on the first number of references, and a second download weight of the mini-program page is calculated based on the second number of references.
[0027] The download weight of the mini-program page is determined based on the first download weight and the second download weight.
[0028] The download order of the mini-program pages is sorted according to their download weight.
[0029] In some embodiments, the resource package download order determination unit includes a page resource loading order sorting subunit, which is specifically used for:
[0030] Based on the page resource tree, determine the first number of times the page resource is directly used and the second number of times the page resource is indirectly used;
[0031] Calculate the first loading weight of the page resource based on the first number of uses;
[0032] Calculate the second loading weight of the page resource based on the second number of uses;
[0033] For any of the page resources, the loading weight of the page resource is determined based on the first loading weight and the second loading weight;
[0034] The loading order of the page resources is sorted based on their loading weights.
[0035] In some embodiments, the sub-packaging unit is specifically used for:
[0036] According to the page resource loading order, the page resources in the mini program source code are divided into packages to obtain the page resource package, so that the resources in the page resource package are sorted according to the page resource loading order;
[0037] Based on the location of the resources in the page resource package, construct the package mapping table.
[0038] In some embodiments, the mini-program resource processing device further includes:
[0039] The mini-program loading information acquisition unit is used to obtain mini-program loading information in response to the mini-program pre-loading instruction triggered in the configuration environment of the parent program.
[0040] The page resource package download unit is used to download a portion of the page resource package based on the resource package download order and package mapping relationship table in the mini-program loading information;
[0041] The preloading unit is used to preload the page based on the downloaded page resource package to obtain page preload data;
[0042] A caching unit is used to store the preloaded page data in the cache of the parent program.
[0043] In some embodiments, the mini-program resource processing device further includes a parsing unit, which is specifically used for:
[0044] In response to a mini-program parsing instruction triggered in the configuration environment of the parent program, the page preload data in the cache of the parent program is mapped to the memory of the parent program according to the package mapping table, so as to parse the page preload data in the memory of the parent program.
[0045] This application also provides an electronic device, including a processor and a memory, wherein the memory stores multiple instructions; the processor loads instructions from the memory to execute steps in any of the applet resource processing methods provided in this application.
[0046] This application also provides a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute steps in any of the applet resource processing methods provided in this application.
[0047] This application embodiment can be applied to the server side. First, the source code file of the mini-program is obtained; then, the page jump information of the mini-program in the source code file is identified; then, based on the page jump information, a page weight graph and a page resource tree of the mini-program pages are constructed; then, according to the page weight graph and the page resource tree, the download order of resource packages is determined; then, the source code file of the mini-program is divided into packages to obtain page resource packages and a package mapping table; finally, according to the download order of resource packages and the package mapping table, mini-program loading information is generated; the mini-program loading information indicates that the page resource packages of the mini-program are loaded in the configuration environment of the parent program.
[0048] In this application, the page navigation information of a mini-program can indicate the correlation between mini-program pages and the number of times page resources are used. A page weight graph constructed using this navigation information can determine which mini-program pages need to be downloaded and loaded first, and which can be downloaded and loaded later. A page resource tree constructed using this navigation information can determine which page resources need to be loaded first. By subdividing the mini-program source code files and obtaining a package mapping table, on-demand loading can be achieved through the location of resources in the package mapping table. Through mini-program loading information, the configuration environment of the parent program on the client can prioritize downloading the page resource packages corresponding to key pages, and prioritize loading the key page resources within those packages. This allows information on key pages to be displayed ahead of time without waiting for all page resources of the mini-program to load, reducing initial loading time and memory usage, and improving the efficiency of mini-program resource processing. Attached Figure Description
[0049] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1a This is a schematic diagram of a scenario illustrating the method for processing mini-program resources provided in an embodiment of this application;
[0051] Figure 1b This is a flowchart illustrating the method for processing mini-program resources provided in an embodiment of this application;
[0052] Figure 1c This is a schematic diagram of the structure of the resource package provided in the embodiments of this application;
[0053] Figure 1d This is a schematic diagram of the page weight map provided in the embodiments of this application;
[0054] Figure 1e This is a schematic diagram of the page resource tree provided in an embodiment of this application;
[0055] Figure 2a This is a schematic diagram of the process by which the mini-program resource processing method provided in this application is executed by the server;
[0056] Figure 2b This is a schematic diagram of the client loading sub-package process provided in an embodiment of this application;
[0057] Figure 2c This is a schematic diagram of the client-side parsing of page resources provided in an embodiment of this application;
[0058] Figure 3a This is a schematic diagram of the structure of the mini-program resource processing device provided in the embodiments of this application;
[0059] Figure 3b This is a schematic diagram of the structure of a mini-program resource processing device provided in another embodiment of this application;
[0060] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0061] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0062] This application provides a method, apparatus, electronic device, and storage medium for processing mini-program resources.
[0063] Specifically, the mini-program resource processing device can be integrated into an electronic device, such as a terminal or server. The terminal can be a mobile phone, tablet, smart Bluetooth device, laptop, or personal computer (PC); the server can be a single server or a server cluster consisting of multiple servers.
[0064] In some embodiments, the mini-program resource processing device can also be integrated into multiple electronic devices, such as multiple terminals, and the mini-program resource processing method of this application can be implemented by multiple terminals. This application does not impose any limitations on this.
[0065] In some embodiments, the terminal can also be used as a server to implement some or all of the functions of a server.
[0066] For example, refer to Figure 1a , Figure 1a This is a schematic diagram of a scenario for the mini-program resource processing method provided in this application embodiment.
[0067] like Figure 1aAs shown, this application scenario can include a server 100 and a client 200, wherein the server 100 can communicate with the client 200. Both the server 100 and the client 200 can be equipped with a mini-program resource processing platform. The mini-program resource processing platform on the server 100 can identify page jump information, construct a page weight graph and page resource tree, and determine the download order and sub-packetization of resource packages. The mini-program resource processing platform on the client 200 can download and load page resource packages. In practical applications, the mini-program resource processing platform on server 100 can identify mini-program page jump information in the mini-program source code file, construct a page weight graph and page resource tree based on the page jump information, determine the download order of resource packages according to the page weight graph and page resource tree, and divide the mini-program source code file into packages to obtain page resource packages and package mapping relationship tables. The mini-program resource processing platform on server 100 can also generate mini-program loading information according to the resource package download order and package mapping relationship table. The mini-program loading information indicates that the page resource packages of the mini-program are loaded in the configuration environment of the parent program. The mini-program resource processing platform on client 200 can obtain the mini-program loading information, download part of the page resource packages based on the resource package download order and package mapping relationship table in the mini-program loading information. The mini-program resource processing platform on client 200 can also perform page preloading based on the downloaded page resource packages, obtain page preloading data, and then store the page preloading data in the cache of the parent program.
[0068] in, Figure 1a In this scenario, the server 100 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. This application does not impose any restrictions on these aspects.
[0069] in, Figure 1a In this scenario, the client 200 can be a mobile terminal, such as a smartphone, tablet, laptop, or smartwatch; or a fixed terminal, such as a desktop computer. This application does not impose any restrictions on this.
[0070] in, Figure 1a The scenario shown includes a server 100 and a client 200. In other possible implementation environments, there may be more servers 100 and clients 200.
[0071] The following sections provide detailed descriptions of each example. It should be noted that the sequence numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0072] In this embodiment, a method for processing mini-program resources is provided. This method can be executed by an electronic device, which may be... Figure 1a The server shown is 100. (Example) Figure 1b As shown, the specific process of this mini-program resource processing method can be as follows:
[0073] 110. Obtain the source code file of the mini program.
[0074] Mini-programs are a type of lightweight application that typically runs on mobile device application platforms. They can be used without installation, consume few system resources, and start up quickly. A mini-program includes multiple components or services to achieve a specific function; these components or services may include, for example, a user interface, data processing, network requests, etc. For instance, in some embodiments, a mini-program may be a game mini-program, a shopping mini-program, a payment mini-program, etc.
[0075] The source code files of a mini-program refer to a collection of various files used for developing and running the mini-program, including but not limited to page files, style files, script files, and configuration files. These files together constitute the core content of the mini-program, ensuring that it can run normally within the parent program. For example, in some implementations, page files are used to define the page structure of the mini-program, including page elements and layout; style files are used to define the page styles of the mini-program, including colors, fonts, layouts, etc.; script files are used to implement the page logic of the mini-program, including page interaction logic and data processing functions; and configuration files are used to define the global configuration of the mini-program, including basic mini-program information, page paths, network requests, etc.
[0076] 120. Identify the page jump information of the mini program in the mini program source code file.
[0077] Among them, the page jump information of the mini program refers to the reference information when multiple pages in the mini program jump, as well as the usage information of the page resources corresponding to each page when jumping.
[0078] In this context, "multiple pages" refers to the numerous pages contained within a mini-program, which together constitute its main functional modules. These pages represent all visible interfaces within the mini-program and can be single pages, combinations of multiple pages, or complex multi-level page structures. Pages can be categorized in various ways, including but not limited to the homepage, function pages, settings pages, and detail pages. The homepage is typically the entry point to the mini-program, allowing users to access other pages or functions. Function pages provide specific functionalities, such as shopping cart pages and search results pages. Settings pages allow users to modify the mini-program's configuration options. Detail pages display detailed information about specific items, such as product details and article details. There are certain referencing relationships between multiple pages, such as navigating from one page to another via hyperlinks or button clicks. These referencing relationships are not limited to simple navigation but can also include data transfer and state synchronization.
[0079] For example, in some embodiments, the specific structure of a page may include a header, body, and footer. The header may contain a navigation bar, the body displays the main content area, and the footer may contain copyright information, etc. The homepage may include a top navigation bar, a scrolling ad area, a recommendation list area, and contact information at the bottom. Each page has its specific function; the homepage can display the latest news or recommended content; function pages can provide specific services, such as payment and settings; and settings pages allow users to modify personal information and account settings. Each page supports user interaction with the mini-program, such as clicking, swiping, and touching. On the details page, users can swipe to view more images and click the purchase button to enter the payment process.
[0080] In this context, "reference information" refers to the logical connections and dependencies between pages. Logical connections between pages refer to the links established through various means, such as navigating from one page to another via hyperlinks, button clicks, or other user interactions. Logical connections also include data transfer between pages, such as parameter passing and state sharing. Dependencies refer to data and functional dependencies between pages. For example, a page may depend on data from another page to display or function correctly. Dependencies also include the page loading order; some pages may need to load before others.
[0081] Usage information refers to the specific details of how page resources are used on the page during page navigation. Usage information helps reduce the loading of redundant resources and improves the performance of real-time applications. Usage information can include: resource file identifiers, which are information used to uniquely identify page resources, such as page resource names and page resource identity identifiers; page resource purpose, which refers to the specific function or role of the page resource on the page; usage method, which refers to how the page resource is used on the page; usage frequency, which refers to the number of times or frequency of page resource usage on the page; and dependencies, which refer to the dependencies between page resources. Dependencies determine whether a page resource is used directly or indirectly.
[0082] For example, in some implementations, when identifying page navigation information in the mini-program source code files, the IDE (Integrated Development Environment) first traverses and loads all source code files of the mini-program based on the user-defined project path or default path. These source code files typically include WXML (page structure), WXSS (style sheets), JS (logic code), and JSON (configuration files, such as page configuration and project configuration). Then, the IDE reads app.json (project configuration file) and page.json (page configuration file) for each page to obtain the mini-program's page structure information, including the path, window appearance, and navigation bar style of each page. Next, the IDE parses the WXML file to construct a page reference graph for subsequent processing. During the WXML file parsing process, the IDE identifies various tags, including... <navigator>Tags (for page link components) define the navigation relationships between pages. Then, the IDE reads and analyzes the JS file, paying particular attention to API (Application Programming Interface) calls related to page navigation. These calls provide the logic and path information for page navigation. Next, the IDE traverses the page reference graph of the WXML file, for each... <navigator>The IDE will read the URL attribute of the tag (which specifies the target page path to jump to) and identify the reference information from the page jump path.
[0083] 130. Based on the page jump information of the mini program, construct the page weight map and page resource tree of the mini program page.
[0084] The page weight graph is a graph structure that represents the importance and relevance of pages within a mini-program. This graph structure helps optimize page loading order and resource management. The page weight graph includes: nodes, where each node represents a page in the mini-program; and lines, where each line represents the navigation relationship between pages. Additionally, the number of times each page is referenced can be assigned to each line.
[0085] For example, in some implementations, the page weight graph is constructed through the following steps:
[0086] Based on the reference information, determine the root node page and leaf node pages, and determine the first reference count between the root node page and the leaf node page, and the second reference count between the leaf node pages.
[0087] The root node page and leaf node pages are used as weight graph nodes. The first reference count is assigned to the weight graph connection between the root node page and the leaf node page, and the second reference count is assigned to the weight graph connection between the leaf node pages, thus obtaining the page weight graph.
[0088] The page resource tree is a tree structure used to represent the hierarchical relationships between pages and their resources within a mini-program. This tree structure helps optimize resource management and the loading process. The main node of the page resource tree typically represents a page within the mini-program; its child nodes typically represent page resources related to the page corresponding to the main node. The hierarchical relationships between child nodes represent the nesting and dependency relationships of page resources.
[0089] For example, in some implementations, the page resource tree is constructed through the following steps:
[0090] Based on the usage information, determine the first type of resource file that is directly used and the second type of resource file that is indirectly used, as well as determine the first number of times the first type of resource file is used and the second number of times the second type of resource file is used.
[0091] The first type of resource file and the second type of resource file are used as resource tree nodes. The first usage count is assigned to the resource tree connection between the first type of resource file and the page, and the second usage count is assigned to the resource tree connection between the first type of resource file and the second type of resource file, to obtain the page resource tree.
[0092] 140. Determine the download order of resource packages based on the page weight map and page resource tree.
[0093] In this context, a resource package refers to a collection that integrates the page resources required by each page of a mini-program for easy loading. In this embodiment, the mini-program contains multiple pages, each associated with a set of page resources. These page resources can be packaged into one or more resource packages. For example, in some embodiments, page resources include, but are not limited to, HTML (HyperText Markup Language, files defining the structure and content of a webpage), CSS (CascadingStyle Sheets, files used to style HTML elements), JavaScript (a scripting language), image files, font files, audio files, video files, and other multimedia files, as well as any other static resources used to build and run the page. Resource packages are organized according to the needs of each page; that is, the page resources are packaged together based on the page's functional characteristics and loading requirements. Different pages may share certain page resources, so resource sharing needs to be considered when organizing resource packages. Specifically, HTML files define the page's structure and content; CSS files define the page's style and layout; JavaScript files implement the page's functionality and interactive effects; image files display visual elements on the page; font files display text on the page; and audio / video files play multimedia content on the page.
[0094] For example, in some embodiments, the resource package structure is organized as "file length, file name, file content". The file length occupies a fixed 8 bytes, the file name occupies 64 bytes, and the file content occupies the actual file size in bytes. See also Figure 1c The structure of resource package A includes "file length 1, file name 1, file content 1, file length 2, file name 2, file name 2"; the structure of resource package B includes "file length 3, file name 3, file content 3, file length 4, file name 4, file name 4".
[0095] The resource package download order refers to the combination of the download order of the corresponding pages in the mini-program and the loading order of page resources. For example, in some embodiments, the priority of different resource packages can be determined based on the importance and usage frequency of the mini-program pages, with resource packages corresponding to key mini-program pages (such as the homepage, login page, etc.) having higher priority. Reference information between mini-program pages can also be analyzed, including but not limited to jump relationships and data dependencies between mini-program pages, to determine the dependencies of resource packages and thus decide the download order. Specifically, resource packages corresponding to key pages (such as the homepage, login page, etc.) should be downloaded first to ensure users can see some content as quickly as possible. For example, the homepage resource package should be downloaded first so that users can quickly see the homepage content when launching the application. Determining the dependencies between resource packages ensures that subsequent resource packages are downloaded only after the preceding resource package is downloaded. For example, if the details page depends on a resource from the list page, the list page resource package should be downloaded before the details page resource package. For example, in some embodiments, the loading order of each page resource is determined based on the usage information of multiple page resources within each mini-program page.
[0096] For example, in some embodiments, when sorting the download order of resource packages corresponding to each page based on the reference information between multiple pages of an e-commerce mini-program, these multiple pages may include: homepage, product list page, product details page, shopping cart page, order confirmation page, user center page, and login page. The reference relationships between these pages can be as follows: a user can directly enter the homepage from the application launch, and can also enter the product list page by clicking on a product from the homepage; a user can enter the product details page by clicking on a product from the product list page; a user can add a product to their shopping cart from the product details page and enter the shopping cart page; a user can enter the order confirmation page from the shopping cart page; a user can enter the user center page from the homepage, and a user can also enter the user center page from the order confirmation page; a user can enter the login page from the homepage, and a user can also enter the login page from the user center page. Based on the above information, the download order of the resource packages for each page can be sorted as follows: The homepage, being the first page users encounter when entering the application, should have its resource package downloaded first; the login page is also a page users are likely to access directly, especially for users who are not yet logged in; the product list page is one of the pages directly accessed from the homepage, so its resource package should be downloaded earlier; the product details page is accessed from the product list page, so its resource package should be downloaded after the product list page; the shopping cart page is accessed from the product details page, so its resource package should be downloaded after the product details page; the order confirmation page is accessed from the shopping cart page, so its resource package should be downloaded after the shopping cart page; the user center page can be accessed from either the homepage or the order confirmation page, so its resource package can be downloaded after the aforementioned pages. Based on the above analysis, the following download order of resource packages can be derived: the first resource package downloaded is the homepage resource package; the second resource package downloaded is the login page resource package; the third resource package downloaded is the product list page resource package; the fourth resource package downloaded is the product details page resource package; the fifth resource package downloaded is the shopping cart page resource package; the sixth resource package downloaded is the order confirmation page resource package; and the seventh resource package downloaded is the user center page resource package.
[0097] In some implementations, the download order of resource packages is determined based on the page weight graph and the page resource tree, including:
[0098] Based on the page weight graph, the download order of the mini-program pages is sorted to obtain the page download order;
[0099] For any mini-program page, the loading order of the page resources corresponding to the mini-program page is sorted according to the page resource tree to obtain the page resource loading order;
[0100] Based on the page download order and page resource loading order, the download order of the resource packages corresponding to the mini-program page is obtained.
[0101] For example, in some implementations, when sorting the download order of mini-program pages according to the page weight graph, the importance of the page is first calculated based on its function and user access frequency. Then, the jump frequency is calculated based on the page jump data in actual user use. Finally, a comprehensive weight value is calculated by combining the page importance and jump frequency. The download order of mini-program pages is then sorted according to the comprehensive weight value of the pages, with mini-program pages with higher weights being downloaded earlier.
[0102] For example, in some implementations, the dependencies and reference counts between page resources are parsed based on the page resource tree, and the weight of each page resource is calculated based on these dependencies and reference counts. The higher the weight of a page resource, the earlier it is loaded, ensuring that page resources with strong dependencies and high reference counts are loaded first.
[0103] For example, in some implementations, the homepage is referenced 4 times; the product list page is referenced once; the product details page is referenced once; the shopping cart page is referenced once; the order confirmation page is referenced once; the user center page is referenced twice; and the login page is referenced twice. Using the number of references as the sole indicator of download weight (in practice, other factors can be combined as needed, such as page importance and user access frequency), based on the above reference counts, we can obtain: the homepage's download weight is 4; the product list page's download weight is 1; the product details page's download weight is 1; the shopping cart page's download weight is 1; the order confirmation page's download weight is 1; the user center page's download weight is 2; and the login page's download weight is 2. Therefore, the page download order is: the first page downloaded is the homepage; the second page downloaded is the user center page; the third page downloaded is the login page; the fourth page downloaded is the product list page; the fifth page downloaded is the product details page; the sixth page downloaded is the shopping cart page; and the seventh page downloaded is the order confirmation page.
[0104] In this embodiment, the number of references between pages is determined based on the page weight graph, and the download weight is calculated. Pages with higher reference counts and greater likelihood of user access are prioritized for download. This means that users can see the main content faster after launching the mini-program, improving overall loading speed. Prioritizing high-weight pages significantly enhances user experience. Users typically want to see the main content or functions of the application as quickly as possible, rather than waiting for all resources to load. By sorting the download order of pages, users can obtain the core functions of the application in a short time, thereby increasing satisfaction. In complex mini-programs, page resources can be very large. If loaded in natural order, users may experience a long waiting time. By sorting the download order of pages, the initial loading time for users can be reduced, allowing them to start using the application faster. Prioritizing the loading of frequently used pages reduces the pressure on memory and storage space. The mini-program does not need to load all resources at once but can load them gradually according to the user's actual needs, thus making better use of system resources. For users with poor network conditions, sorting the download order of pages can better utilize limited bandwidth resources. Prioritizing the loading of key resources ensures that users obtain the main functions of the application in a short time, without affecting the user experience due to network latency.
[0105] In this embodiment, by acquiring and prioritizing page resource usage information, resources crucial for page rendering can be loaded first, thereby accelerating the initial page load speed. A reasonable loading order allows users to gradually see more content during page loading, rather than waiting for all page resources to load completely, improving the user's perceived speed. Prioritizing prevents the loading of certain page resources from blocking the loading of other resources; for example, ensuring that critical styles and script files load before non-critical files avoids long waits for the page to fully load, enabling on-demand resource loading—dynamically loading necessary resources based on user behavior, reducing unnecessary resource loading, and thus improving resource utilization.
[0106] In some implementations, the mini-program page includes a root node page and leaf node pages. The download order of the mini-program pages is sorted according to a page weight graph, including:
[0107] Based on the page weight graph, determine the first reference count between the root node page and the leaf node page, and determine the second reference count between the leaf node pages;
[0108] For any mini-program page, calculate the first download weight of the mini-program page based on the first number of references, and calculate the second download weight of the mini-program page based on the second number of references.
[0109] The download weight of the mini-program page is determined based on the first download weight and the second download weight.
[0110] The download order of mini-program pages is sorted according to their download weight.
[0111] The root page, or root node page, is the first page displayed to the user after the mini-program is launched. It is the user's first entry point into the mini-program and has high importance and priority. For example, in some implementations, the root node page undertakes the main function of guiding users into the mini-program, typically including but not limited to navigation, displaying main content, and providing basic operations. The root node page is at the top level in the mini-program's page structure, usually located at the starting point of the page reference diagram. The root node page can be the mini-program's homepage, and its content typically includes the mini-program's navigation menu, welcome message, latest news, or recommended content; the root node page can also include navigation modules, information display modules, and operation modules.
[0112] In a mini-program's page structure, a leaf node page is a page referenced by other pages. Leaf node pages are typically content display pages, such as detail pages or confirmation pages. For example, in some implementations, users can complete operations like reading, confirming, and submitting on a leaf node page, and then return to the parent page or close the page. The content of a leaf node page usually includes detailed text information, charts, multimedia content, etc.; leaf node pages may contain operation buttons or options, such as "Buy," "Confirm Order," "Share," etc.; leaf node pages may also provide a back button or other navigation options, allowing users to return to the previous page or the homepage.
[0113] The reference count reflects the frequency of page navigation and can be used to optimize the download order of page resource packages and page loading strategies.
[0114] Download weight determines the priority of page resource packages when loaded on the client side. The download weight between pages refers to the download priority assigned to pages based on factors such as page importance and usage frequency. For example, in some implementations, page download weight can be determined by factors such as page importance, user access frequency, and dependencies between pages. Weighted average methods, machine learning models, and other methods can be used to determine page download weight.
[0115] For example, in some implementations, the first reference count is multiplied by a first preset value when the root node page references a leaf node page, which is used as the first download weight; the second reference count is multiplied by a second preset value when each leaf node page references another leaf node page, which is used as the second download weight; the sum of the first and second download weights of each mini-program page is used as the download weight of each mini-program page, and the page download order is obtained based on the comparison result of the download weights of each mini-program page.
[0116] For example, in some implementations, see Figure 1d Based on the page navigation information of the mini-program, a page weight graph is constructed, where each node in the page weight graph represents a mini-program page, and the numbers on the lines connecting the nodes represent the number of references. The download weight of a page can be expressed as: W = m * r root + n * r leaf, where W represents the download weight; m represents the weight corresponding to the root node page; n represents the weight corresponding to the leaf node page; r root represents the number of references between the root node page and the leaf node page; and r leaf represents the number of references between the leaf nodes. Assuming m is 10 and n is 1, the download weights and download order shown in Table 1 can be obtained.
[0117] Table 1 Download Weight and Download Order
[0118] Page Name Representation Download weight Download order Root node page 10*(4+3+2)+1*(4+3+2) 99 1 Leaf node page 1 10*4+1*(3+2) 45 2 Leaf node page 2 10*3+1*(2+2+1) 35 3 Leaf node page 3 10*2+1*(1+1) 22 4 Leaf node page 4 10*0+1*(3+2+1) 6 5
[0119] In this embodiment, the first download weight of each page is calculated based on the first reference count between the root node page and the leaf node pages. This identifies which leaf node pages are referenced most frequently, and these pages have higher download weights. Prioritizing the loading of these pages ensures that users can see and use the most critical content more quickly. The second download weight of each page is calculated based on the second reference count. This identifies which leaf node pages are navigated to more frequently, and these pages also have higher download weights. This ensures that users can quickly navigate to the pages they need while browsing, improving the user experience.
[0120] In some implementations, the loading order of page resources corresponding to a mini-program page is sorted according to the page resource tree, including:
[0121] Based on the page resource tree, determine the first number of times the directly used page resource is used, and determine the second number of times the indirectly used page resource is used.
[0122] Calculate the first load weight of the page resource based on the first usage count;
[0123] Calculate the second load weight of the page resource based on the second usage count;
[0124] For any given page resource, the loading weight of the page resource is determined based on the first loading weight and the second loading weight.
[0125] The loading order of page resources is sorted based on the loading weight of page resources.
[0126] Direct use refers to the process of directly loading and using page resources within a mini-program; indirect use refers to the process of indirectly loading and using page resources through middleware or frameworks. Loading weight refers to the different loading priorities assigned to page resources based on their importance and frequency of use on the page.
[0127] For example, in some implementations, the product of the corresponding preset weight value and the first number of times it is used directly is used as the first loading weight of the page resource; the product of the corresponding preset weight value and the second number of times it is used indirectly is used as the second loading weight of the page resource; the sum of the first loading weight and the second loading weight is used as the loading weight of the page resource, and the loading order of the page resources is obtained according to the comparison result of the loading weight of each page resource.
[0128] For example, in some implementations, see Figure 1e Based on the page navigation information of the mini-program, a page resource tree is constructed. In the page resource tree, the main node is the page, and the child nodes are page resources. R1 indicates that the corresponding preset weight value is used directly, and R2 indicates that the corresponding preset weight value is used indirectly. The loading weight is represented as: V = R1C1 + R2C2 + ... + RnCn, where V represents the loading weight, Rn indicates whether the current page resource is used directly or indirectly, R1 > R2, and C represents the number of times it is used. Let R1 be 100 and R2 be 10. The loading order of the page resources can be obtained as follows: First page resource, V1 = 100*1 + 2*10; Second page resource, V2 = 100*1 + 1*10; Third page resource, V3 = 100*1 + 2*10; Fourth page resource, V4 = 100*1 + 1*10; Fifth page resource, V5 = 10*1; Sixth page resource, V6 = 30*3; Seventh page resource, V7 = 10*1; Eighth page resource, V8 = 10*1.
[0129] In this embodiment, by calculating the first and second loading weights of page resources, frequently used page resources can be loaded first, thereby improving page loading speed. By prioritizing loading weights, progressive loading can be achieved, loading the content most relevant to the user first and then gradually loading other content, thus improving user experience. Calculating loading weights can prevent the loading of critical resources from being blocked due to the loading of non-critical resources, thereby reducing page loading blocking time. Calculating loading weights also enables on-demand resource loading, dynamically loading necessary resources and reducing unnecessary resource loading, thereby improving resource utilization. Optimizing the loading order allows for the rational allocation of network bandwidth, prioritizing the loading of critical resources, thus improving bandwidth utilization efficiency.
[0130] 150. Divide the source code files of the mini program into packages to obtain page resource packages and package mapping relationship tables.
[0131] Subpackaging, also known as mini-program page resource packaging, refers to the process of integrating page resources from mini-program source code files into one or more resource packages. This optimizes resource loading and improves loading efficiency and user experience. For example, in some implementations, different types of page resources can be first categorized according to certain rules for easier packaging; then, the categorized page resources are integrated based on page reference relationships and functional requirements to form logically related resource packages. During the packaging process, page resources can be compressed and merged to reduce file size and improve loading efficiency.
[0132] For example, in some implementations, page resource packages include main package type resource packages and sub-package type resource packages. The main package type refers to a resource package type that plays a core role in the mini-program, typically containing basic resource files that must be loaded when the mini-program starts. For example, in some implementations, the main package type resource package may be the resource package corresponding to the root node page. The sub-package type refers to other resource package types in the mini-program besides the main package, typically containing resource files required by specific functions or modules in the application. For example, in some implementations, the sub-package type resource package may be the resource package corresponding to the leaf node page.
[0133] In some implementations, the mini-program source code files are divided into packages to obtain page resource packages and package mapping relationship tables, including:
[0134] Based on the page resource loading order, the page resources in the mini program source code are divided into packages to obtain page resource packages, so that the resources in the page resource packages are sorted according to the page resource loading order;
[0135] Based on the location of resources in the page resource package, construct a package mapping table.
[0136] The package mapping table is a table that records the location information of each page resource package and its contained resource page resources in the mini program. This table is used to quickly find and load the required page resources, and optimize resource management and loading processes.
[0137] 160. Generate mini-program loading information based on the resource package download order and package mapping table; the mini-program loading information indicates the loading of the mini-program's page resource package in the parent program's configuration environment.
[0138] The parent program refers to the core program containing all mini-programs. It manages and coordinates the operation of each mini-program, providing basic functions and services to ensure overall operation and performance optimization. For example, in some implementations, the parent program can handle mini-program initialization, including loading basic configurations and initializing the environment; it can also manage page navigation and routing to ensure smooth transitions between pages; it can manage and schedule resource files within the mini-program, including page files, style files, script files, and media files; it can maintain and manage the global state of the mini-program to ensure data consistency and integrity; and it can handle user interaction events, such as clicks and swipes, triggering corresponding business logic. Loading refers to the process of downloading page resource packages from the server to the client and loading them into the mini-program. Loading page resource packages may include steps such as parsing page resources, executing relevant scripts, and rendering the page. These steps ensure the page resource packages are correctly loaded and presented to the user.
[0139] In this embodiment, a method for processing mini-program resources applied to a client is also provided. This method can be executed by an electronic device, which may be... Figure 1a The client 200 is shown. The specific process of this mini-program resource processing method can be as follows:
[0140] A. Respond to the mini-program preloading instruction triggered in the configuration environment of the parent program to obtain mini-program loading information;
[0141] B. Based on the resource package download order and package mapping relationship table in the mini-program loading information, download some page resource packages;
[0142] C. Based on the downloaded page resource package, perform page preloading to obtain page preload data;
[0143] D. Store the preloaded page data in the cache of the parent program.
[0144] As can be seen, in this embodiment, the reference information between multiple pages can indicate the reference dependencies and reference counts between various pages within the mini-program. Through these reference relationships, it can be determined which page resource packages need to be downloaded and loaded first, and which page resource packages can be downloaded and loaded later. By controlling the resource package download order, after the client loads the main package type resource package, it can prioritize downloading the sub-package type resource packages corresponding to key pages and load the resource files within those sub-package types. This allows information on key pages to be displayed ahead of time without waiting for all resource files in the mini-program to be loaded, reducing initial loading time and memory usage, and improving the efficiency of mini-program resource processing.
[0145] In some implementations, after storing the page preload data in the cache of the parent program, the method further includes:
[0146] In response to the mini-program parsing instruction triggered in the parent program's configuration environment, the page preload data in the parent program's cache is mapped to the parent program's memory according to the package mapping table, so that the page preload data can be parsed in the parent program's memory.
[0147] Parsing refers to the process on the client side of decompressing the downloaded page resource package and parsing it into executable code or displayable content. Specifically, decompression refers to restoring the downloaded page resource package from a compressed format to its original file format; code parsing refers to converting the code files in the page resource package into an executable form; and content rendering refers to rendering the static resources in the page resource package into user-visible content.
[0148] In some embodiments, when the client parses page resources, the loader intercepts the request to load mini-program resources, obtains the name of the currently requested page resource, and confirms that the requested page resource has not yet been parsed. The loader reads the package mapping table and obtains the location information of the page resource in the page resource package by using the name of the page resource. Using the obtained location information, a file random access tool is used to quickly access the start and end positions of the page resource in the page resource package, extract the page resource file stream, and return the page resource file stream to the loader. The resource package parsing logic is executed synchronously to parse the page resource to local storage.
[0149] In this embodiment, even without parsing all page resource packages, access to the page resources of the mini-program can still be achieved, bypassing the time-consuming process of parsing page resource packages and improving the loading efficiency of the mini-program. As can be seen, in this embodiment, mini-program page jump information can indicate the correlation between mini-program pages and the usage frequency of page resources. The page weight graph constructed using the mini-program page jump information can determine which mini-program pages need to be downloaded and loaded first, and which can be downloaded and loaded later. The page resource tree constructed using the mini-program page jump information can determine which page resources need to be loaded first. By subdividing the mini-program source code files and obtaining a package mapping table, on-demand loading can be achieved through the location of resources in the package mapping table. Through mini-program loading information, in the configuration environment of the client's parent program, the page resource packages corresponding to key pages can be downloaded first, and the key page resources in those packages can be loaded first. Information in key pages can be displayed in advance without waiting for all page resources of the mini-program to be loaded, reducing initial loading time and memory usage, and improving the efficiency of mini-program resource processing.
[0150] The method described in the above embodiments will be further described in detail below.
[0151] A method for processing mini-program resources can be executed by an electronic device. In this embodiment, the method will be described in detail by taking the execution of the method by a server as an example.
[0152] like Figure 2a As shown, the specific process of a mini-program resource processing method is as follows:
[0153] 210. Obtain the source code files
[0154] For example, in some embodiments, when an IDE compiles a mini-program source code file, it first obtains the mini-program source code file based on the mini-program source code path during the compilation process.
[0155] 220. Parsing source code files
[0156] For example, in some embodiments, the page configuration in the app.json file in the source code is read to obtain all page entry information of the current mini program, and the page element (wxml) file and js file are parsed.
[0157] 230. Construct a page weight graph
[0158] For example, in some embodiments, based on the wxml file <navigator>Tag recognition and page reference information location: Traverse the wxml, identify the navigator tag, obtain the url attribute of the navigator tag, extract the attribute and match it with the page information in step 210. If a match is found, increment the reference count by 1; identify the page jump path based on navigation-related functions in the js file, and identify the target page information from the page jump path. For each target path jump information identified, increment the reference count corresponding to the page jump start point and page jump end point in the page weight graph by 1; finally, obtain the complete page weight graph.
[0159] 240. Construct the page resource tree
[0160] For example, in some embodiments, the usage information of page resources corresponding to each mini-program page is identified separately: the page resources directly used by the current page are identified by the import and require syntax, and the directly used page resources are added to the page resource tree; the indirectly used page resources are identified (also by the import and require syntax), and the indirectly used page resources are added to the page resource tree.
[0161] 250. Divide the source code files of the mini-program into multiple packages.
[0162] For example, in some embodiments, the page weight graph and page resource tree obtained in steps 230 and 240 are used to obtain the page download order and page resource loading order, and the page resources corresponding to the root node page are packaged to obtain a main package type page resource package, and the page resources corresponding to the leaf node page are packaged to obtain a sub-package type page resource package.
[0163] For example, in some embodiments, see Figure 2b When the client loads a resource package, during the download process, if the currently downloaded mini-program is already loading, the downloader will match the package mapping table in the current mini-program version update information. Using the package mapping table, it identifies the resource package from the file stream of the page resource package read by the download module. If the currently downloaded resource package contains resources that the mini-program to be loaded depends on, the cache address of the currently read page resource package is directly provided to the loader. The loader reads the currently dependent resource package from the downloader's runtime cache and uses it. Following the original download logic, the loader downloads the resource package to local memory and completes the subsequent parsing process.
[0164] In this embodiment, by directly mapping the resource package cache to the loader's memory space during the resource package download process, the problem of the original solution requiring the resource package to be downloaded and parsed before the mini-program can be loaded is solved, thus improving the loading efficiency of the mini-program.
[0165] For example, in some embodiments, see Figure 2c When the client parses page resources, the loader intercepts the request to load resources in the mini-program, obtains the name of the requested page resource, and confirms that the requested page resource has not yet been parsed. The loader reads the package mapping table and obtains the location information of the page resource in the resource package by using the name of the page resource. Using the obtained location information, a file random access tool is used to quickly access the start and end positions of the page resource in the resource package, extract the resource file stream, and return the resource file stream to the loader. The resource package parsing logic is executed synchronously, parsing the resource file to local storage.
[0166] In this embodiment, even without parsing all resource packages, access to the mini-program's resource files can still be achieved, bypassing the time-consuming process of resource package parsing and improving the loading efficiency of the mini-program.
[0167] As can be seen from the above, in this embodiment of the application, the reference count between pages is determined based on the page weight graph, and the download weight is calculated. This allows for the priority downloading of pages with higher reference counts and those more likely to be accessed by users. This means that users can see the main content faster after launching the mini-program, improving the overall loading speed. Prioritizing the loading of high-weight pages can significantly improve the user experience. Users typically want to see the main content or functions of the application as soon as possible, rather than waiting for all resources to load. By sorting the download order of pages, users can obtain the core functions of the application in a short time, thereby improving satisfaction. In complex mini-programs, page resources can be very large. If loaded in natural order, users may experience a long waiting time. By sorting the download order of pages, the initial loading time for users can be reduced, allowing them to start using the application faster. Prioritizing the loading of frequently used pages can reduce the pressure on memory and storage space. The mini-program does not need to load all resources at once, but rather loads them gradually according to the user's actual needs, thus making better use of system resources. For users with poor network conditions, sorting the download order of pages can make better use of limited bandwidth resources, prioritize loading critical resources, and ensure that users can obtain the main functions of the application in a short time without affecting the user experience due to network latency.
[0168] Furthermore, by calculating the first download weight of each page based on the first reference count between the root node page and leaf node pages, we can identify which leaf node pages are referenced most frequently. These pages have higher download weights, and prioritizing the loading of these pages ensures that users can see and use the most crucial content more quickly. By calculating the second download weight of each page based on the second reference count, we can identify which leaf node pages are navigated to more frequently. These pages also have higher download weights, ensuring that users can quickly navigate to the pages they need while browsing, thus improving the user experience.
[0169] Furthermore, by acquiring and prioritizing page resource usage information, resources crucial for page rendering can be loaded first, thus accelerating the initial page load speed. A reasonable loading order allows users to gradually see more content as the page loads, rather than waiting for all page resources to complete, improving the perceived speed for the user. Prioritizing resources prevents the loading of certain resources from blocking the loading of others; for example, ensuring that critical styles and script files load before non-critical files avoids long waits for the page to fully load, enabling on-demand resource loading—dynamically loading necessary resources based on user behavior, reducing unnecessary resource loading, and thus improving resource utilization.
[0170] Furthermore, by calculating the first and second load weights of page resources, frequently used page resources can be loaded first, thereby improving page loading speed. Ranking by load weight allows for progressive loading, loading the content most relevant to the user first and then gradually loading other content, thus improving user experience. Calculating load weights can prevent the loading of critical resources from being blocked due to the loading of non-critical resources, thereby reducing page loading blocking time. Calculating load weights also enables on-demand resource loading, dynamically loading necessary resources and reducing unnecessary resource loading, thus improving resource utilization. Optimizing the loading order allows for the rational allocation of network bandwidth, prioritizing the loading of critical resources, thereby improving bandwidth utilization efficiency.
[0171] It is understood that, in the embodiments of this application, there are related data such as reference information between multiple pages of the mini-program and usage information of multiple page resources corresponding to the mini-program page. When the following embodiments of this application are applied to specific products or technologies, permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0172] To better implement the above methods, this application also provides a mini-program resource processing device, which can be integrated into an electronic device, such as a terminal. The terminal can be a mobile phone, tablet computer, laptop computer, personal computer, or similar device.
[0173] For example, in this embodiment, the device of this application embodiment will be described in detail by taking the integration of the mini-program resource processing device on the server side as an example. For example, as Figure 3a As shown, the mini-program resource processing device may include a file acquisition unit 301, a file recognition unit 302, a weight graph and resource tree construction unit 303, a resource package download order determination unit 304, a sub-package unit 305, and a loading information generation unit 306, as follows:
[0174] File acquisition unit 301 is used to acquire the source code file of the mini program;
[0175] The file recognition unit 302 is used to recognize mini-program page jump information in the mini-program source code file;
[0176] The weight graph and resource tree construction unit 303 is used to construct the page weight graph and page resource tree of the mini program page based on the mini program page jump information;
[0177] The resource package download order determination unit 304 is used to determine the resource package download order based on the page weight map and the page resource tree;
[0178] Sub-packaging unit 305 is used to sub-package the mini-program source code file to obtain page resource packages and package mapping relationship tables;
[0179] The loading information generation unit 306 is used to generate mini-program loading information according to the resource package download order and package mapping relationship table; the mini-program loading information indicates that the page resource package of the mini-program is loaded in the configuration environment of the parent program.
[0180] In some embodiments, the resource package download order determination unit is further configured to:
[0181] Based on the page weight graph, the download order of the mini-program pages is sorted to obtain the page download order;
[0182] For any mini-program page, the loading order of the page resources corresponding to the mini-program page is sorted according to the page resource tree to obtain the page resource loading order;
[0183] Based on the page download order and page resource loading order, the download order of the resource packages corresponding to the mini-program page is obtained.
[0184] In some embodiments, the mini-program page includes a root node page and leaf node pages, and the resource package download order determination unit includes a page download order sorting subunit, which is specifically used for:
[0185] Based on the page weight graph, determine the first reference count between the root node page and the leaf node page, and determine the second reference count between the leaf node pages;
[0186] For any mini-program page, calculate the first download weight of the mini-program page based on the first number of references, and calculate the second download weight of the mini-program page based on the second number of references.
[0187] The download weight of the mini-program page is determined based on the first download weight and the second download weight.
[0188] The download order of mini-program pages is sorted according to their download weight.
[0189] In some embodiments, the resource package download order determination unit includes a page resource loading order sorting subunit, which is specifically used for:
[0190] Based on the page resource tree, determine the first number of times the directly used page resource is used, and determine the second number of times the indirectly used page resource is used.
[0191] Calculate the first load weight of the page resource based on the first usage count;
[0192] Calculate the second load weight of the page resource based on the second usage count;
[0193] For any given page resource, the loading weight of the page resource is determined based on the first loading weight and the second loading weight.
[0194] The loading order of page resources is sorted based on the loading weight of page resources.
[0195] In some embodiments, the sub-packaging unit is specifically used for:
[0196] Based on the page resource loading order, the page resources in the mini program source code are divided into packages to obtain page resource packages, so that the resources in the page resource packages are sorted according to the page resource loading order;
[0197] Based on the location of resources in the page resource package, construct a package mapping table.
[0198] For example, in this embodiment, the device of this application embodiment will be described in detail by taking the integration of the mini-program resource processing device into the client as an example. For example, as Figure 3b As shown, the mini-program resource processing device may include a mini-program loading information acquisition unit 307, a page resource package download unit 308, a preloading unit 309, and a caching unit 310, as follows:
[0199] The mini-program loading information acquisition unit 307 is used to acquire mini-program loading information in response to a mini-program pre-loading instruction triggered in the configuration environment of the parent program.
[0200] Page resource package download unit 308 is used to download part of the page resource package based on the resource package download order and package mapping relationship table in the mini program loading information;
[0201] The preloading unit 309 is used to preload the page based on the downloaded page resource package to obtain page preload data;
[0202] Cache unit 310 is used to store preloaded page data in the cache of the parent program.
[0203] In some embodiments, the mini-program resource processing device further includes a parsing unit, which is specifically used for:
[0204] In response to the mini-program parsing instruction triggered in the parent program's configuration environment, the page preload data in the parent program's cache is mapped to the parent program's memory according to the package mapping table, so that the page preload data can be parsed in the parent program's memory.
[0205] In practice, each of the above modules or units can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units, please refer to the previous method embodiments, which will not be repeated here.
[0206] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0207] As can be seen from the above, the embodiments of this application can improve the efficiency of mini-program resource processing.
[0208] This application also provides an electronic device, which can be a terminal, a server, or other similar device. The terminal can be a mobile phone, tablet computer, laptop computer, personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers, etc.
[0209] In this embodiment, a laptop computer will be used as an example for detailed description. For example, ... Figure 4 As shown, it illustrates a structural schematic diagram of the electronic device involved in the embodiments of this application, specifically:
[0210] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will understand that... Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:
[0211] The processor 401 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 402, and by calling data stored in the memory 402, it performs various functions and processes data, thereby performing overall detection of the electronic device. In some embodiments, the processor 401 may include one or more processing cores; in some embodiments, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applets, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 401.
[0212] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0213] The electronic device also includes a power supply 403 that supplies power to the various components. In some embodiments, the power supply 403 can be logically connected to the processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 403 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0214] The electronic device may also include an input module 404, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0215] The electronic device may also include a communication module 405. In some embodiments, the communication module 405 may include a wireless module, through which the electronic device can perform short-range wireless transmission, thereby providing users with wireless broadband internet access. For example, the communication module 405 can be used to help users send and receive emails, browse web pages, and access streaming media, and can also communicate with a server.
[0216] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device loads the executable files corresponding to the processes of one or more applications into the memory 402 according to the following instructions, and the processor 401 runs the applications stored in the memory 402 to realize various functions, as follows:
[0217] First, obtain the mini-program source code file; then, identify the mini-program page navigation information in the source code file; next, based on the page navigation information, construct a page weight graph and page resource tree for the mini-program pages; then, determine the download order of resource packages according to the page weight graph and page resource tree; next, divide the mini-program source code file into packages to obtain page resource packages and package mapping relationship tables; finally, generate mini-program loading information according to the resource package download order and package mapping relationship table; the mini-program loading information indicates that the page resource packages of the mini-program are loaded in the configuration environment of the parent program.
[0218] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0219] As can be seen from the above, the embodiments of this application can improve the efficiency of mini-program resource processing.
[0220] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0221] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute steps in any of the applet resource processing methods provided in embodiments of this application. For example, the instructions can execute the following steps:
[0222] First, obtain the mini-program source code file; then, identify the mini-program page navigation information in the source code file; next, based on the page navigation information, construct a page weight graph and page resource tree for the mini-program pages; then, determine the download order of resource packages according to the page weight graph and page resource tree; next, divide the mini-program source code file into packages to obtain page resource packages and package mapping relationship tables; finally, generate mini-program loading information according to the resource package download order and package mapping relationship table; the mini-program loading information indicates that the page resource packages of the mini-program are loaded in the configuration environment of the parent program.
[0223] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0224] According to one aspect of this application, a computer program product is provided, comprising a computer program stored in a computer-readable storage medium. The computer program is read and executed by a processor of an electronic device, causing the electronic device to implement the methods provided in the above embodiments.
[0225] Since the instructions stored in the storage medium can execute the steps in any of the mini-program resource processing methods provided in the embodiments of this application, the beneficial effects that any of the mini-program resource processing methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.
[0226] The foregoing has provided a detailed description of a method, apparatus, electronic device, and storage medium for processing mini-program resources according to embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.< / navigator> < / navigator> < / navigator>
Claims
1. A method for processing resources in a mini-program, characterized in that, include: Obtain the source code file of the mini program; Identify the mini-program page jump information in the mini-program source code file; Based on the page jump information of the mini program, construct the page weight graph and page resource tree of the mini program page; The download order of resource packages is determined based on the page weight map and the page resource tree; The source code files of the mini-program are divided into packages to obtain page resource packages and package mapping relationship tables; Based on the download order of the resource packages and the package mapping table, mini-program loading information is generated; the mini-program loading information indicates that the page resource packages of the mini-program are loaded in the configuration environment of the parent program.
2. The method for processing mini-program resources as described in claim 1, characterized in that, The step of determining the download order of resource packages based on the page weight graph and the page resource tree includes: Based on the page weight graph, the download order of the mini-program pages is sorted to obtain the page download order; For any of the aforementioned mini-program pages, the loading order of the page resources corresponding to the mini-program page is sorted according to the page resource tree to obtain the page resource loading order; Based on the page download order and the page resource loading order, the resource package download order of the page resource package corresponding to the mini program page is obtained.
3. The method for processing mini-program resources as described in claim 2, characterized in that, The mini-program page includes a root node page and leaf node pages. The step of sorting the download order of the mini-program pages according to the page weight graph includes: Based on the page weight graph, determine the first number of references between the root node page and the leaf node page, and determine the second number of references between the leaf node pages; For any of the aforementioned mini-program pages, a first download weight of the mini-program page is calculated based on the first number of references, and a second download weight of the mini-program page is calculated based on the second number of references. The download weight of the mini-program page is determined based on the first download weight and the second download weight. The download order of the mini-program pages is sorted according to their download weight.
4. The method for processing mini-program resources as described in claim 2, characterized in that, The step of sorting the loading order of page resources corresponding to the mini-program page according to the page resource tree includes: Based on the page resource tree, determine the first number of times the page resource is directly used and the second number of times the page resource is indirectly used; Calculate the first loading weight of the page resource based on the first number of uses; Calculate the second loading weight of the page resource based on the second number of uses; For any of the page resources, the loading weight of the page resource is determined based on the first loading weight and the second loading weight; The loading order of the page resources is sorted based on their loading weights.
5. The method for processing mini-program resources as described in any one of claims 2 to 4, characterized in that, The process of splitting the source code file of the mini-program into packages to obtain page resource packages and package mapping relationship tables includes: According to the page resource loading order, the page resources in the mini program source code are divided into packages to obtain the page resource package, so that the resources in the page resource package are sorted according to the page resource loading order; Based on the location of the resources in the page resource package, construct the package mapping table.
6. The method for processing mini-program resources as described in claim 1, characterized in that, The method further includes: In response to the mini-program preloading instruction triggered in the configuration environment of the parent program, obtain mini-program loading information; Based on the resource package download order and package mapping relationship table in the mini-program loading information, download part of the page resource package; Based on the downloaded page resource package, page preloading is performed to obtain page preload data; The preloaded data of the page is stored in the cache of the parent program.
7. The method for processing mini-program resources as described in claim 6, characterized in that, After storing the preloaded page data in the cache of the parent program, the method further includes: In response to a mini-program parsing instruction triggered in the configuration environment of the parent program, the page preload data in the cache of the parent program is mapped to the memory of the parent program according to the package mapping table, so as to parse the page preload data in the memory of the parent program.
8. A mini-program resource processing device, characterized in that, The device includes: The file acquisition unit is used to acquire the source code files of the mini-program. The file recognition unit is used to recognize the mini-program page jump information in the mini-program source code file; The weight graph and resource tree construction unit is used to construct the page weight graph and page resource tree of the mini-program page based on the page jump information of the mini-program; The resource package download order determination top unit is used to determine the resource package download order based on the page weight graph and the page resource tree; The sub-packaging unit is used to sub-package the source code file of the mini-program to obtain page resource packages and package mapping relationship tables; The loading information generation unit is used to generate mini-program loading information according to the download order of the resource packages and the package mapping relationship table; the mini-program loading information indicates that the page resource package of the mini-program is loaded in the configuration environment of the parent program.
9. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing multiple instructions; the processor loads instructions from the memory to execute the steps in the applet resource processing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to perform the steps in the applet resource processing method as described in any one of claims 1 to 7.