Self-adaptive H5 resource loading method and device, equipment and storage medium

By listening to network requests of H5 pages and using the native side to process resource acquisition requests, cache resources and optimize memory usage, the problems of slow loading speed and high memory usage of H5 page resources on mobile devices are solved, improving user experience.

CN118981579APending Publication Date: 2024-11-19PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411129481.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-16
Publication Date
2024-11-19

AI Technical Summary

Technical Problem

The H5 page resource loading speed on mobile devices is slow, the memory usage is high and the cache management is poor. The existing technology optimization solutions cannot fundamentally solve these problems.

Method used

By listening to the network requests of the H5 page, identifying the request type, the ordinary request is directly forwarded to the target server, the resource acquisition request is obtained by the native side and cached to the resource database, simulated response data and sent to the H5 page, and optimized memory through intelligent cache management use.

Benefits of technology

It improves resource loading efficiency, optimizes memory usage, solves the problems of slow loading speed and poor cache management, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118981579A_ABST
    Figure CN118981579A_ABST
Patent Text Reader

Abstract

The invention relates to a self-adaptive H5 resource loading method, which comprises the following steps of: monitoring a network request sent by an H5 page, and identifying the type of the network request; if the type of the network request is a common network request, directly forwarding the common network request to a target server, and not intercepting the common network request; and if the type of the network request is a resource acquisition request, intercepting the network request, acquiring a target resource corresponding to the resource acquisition request by using a native end, caching the target resource to a resource database, simulating the target resource into response data of the resource acquisition request by using the native end, and sending the response data to an H5 page. According to the method and the device, the resource request is processed by using the native end, the resource loading efficiency is improved, and the memory use is optimized through an intelligent cache management mechanism, so that the problems of low loading speed, high memory occupation and poor cache management in the prior art are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Web technology, and in particular to an adaptive H5 resource loading method, apparatus, device, and storage medium. Background Technology

[0002] With the rapid development of the mobile internet, mobile applications (Apps) have become an indispensable part of people's daily lives. Among these applications, HTML5 technology is widely used due to its cross-platform compatibility and powerful expressive capabilities. However, in practical applications, the resource loading efficiency and memory management of HTML5 pages have always been problems that urgently need to be solved.

[0003] H5 pages are often developed and displayed to more conveniently and quickly showcase the latest content and layout, such as event pages and product introductions. However, on mobile devices, due to network conditions and device performance limitations, H5 pages often face the following problems when loading resources:

[0004] Slow loading speed: The network environment of mobile devices is relatively unstable, which leads to slow loading speed of H5 page resources and affects user experience.

[0005] High memory usage: Mobile devices have limited memory resources, and loading a large number of resources will lead to high memory usage, thus affecting the performance of applications.

[0006] Poor cache management: Traditional browser caching mechanisms cannot fully utilize the characteristics of mobile devices, resulting in low cache hit rates and repeated downloads of resources.

[0007] To address these issues, existing technologies have proposed several optimization solutions. These include compressing resource files, using CDNs (Content Delivery Networks) to accelerate resource loading, and improving browser cache utilization. However, these methods still have limitations and cannot fundamentally solve the problems of low resource loading efficiency and poor memory management in mobile applications. Summary of the Invention

[0008] The main objective of this invention is to provide an adaptive H5 resource loading method, apparatus, device, and storage medium, aiming to solve the technical problem of slow loading speed in existing H5 page resource loading technologies.

[0009] To achieve the above objectives, the present invention provides an adaptive H5 resource loading method, which includes the following steps:

[0010] Listen for network requests sent by H5 pages and identify the type of the network requests;

[0011] If the network request is a normal network request, the normal network request will be forwarded directly to the target server;

[0012] If the network request is a resource acquisition request, the native client obtains the target resource corresponding to the resource acquisition request, caches the target resource in the resource database, uses the native client to simulate the target resource as the response data of the resource acquisition request, and sends the response data to the H5 page.

[0013] Optionally, the step of monitoring network requests sent by the H5 page includes:

[0014] Use a webview container, network proxy, network hook, or network library interceptor to listen for network requests sent by the H5 page.

[0015] Optionally, after the step of obtaining the target resource corresponding to the resource acquisition request using the native end, the method further includes:

[0016] If the target resource is a video resource that can be played online, the native client will synchronously send the video segment data stream of the video resource to the H5 page, and display the target resource through the H5 page.

[0017] Optionally, after the step of caching the target resource to the resource database, the method further includes:

[0018] Monitor the remaining memory of the device where the resource database is located;

[0019] If the remaining memory is less than a preset value, perform a cache cleanup operation on the resource database;

[0020] If the remaining memory is not less than the preset value, the cached resources in the resource database that have reached the preset cache duration are cleaned up.

[0021] Optionally, after the step of caching the target resource to the resource database, the method further includes:

[0022] When the H5 page sends another resource retrieval request, the data resource library is retrieved through the native terminal.

[0023] If the data resource library contains local cached resources corresponding to the resource acquisition request, the cached resources will be sent to the H5 page.

[0024] If the data resource library does not contain a local cached resource corresponding to the resource acquisition request, the following steps are performed: use the native client to obtain the target resource corresponding to the resource acquisition request, cache the target resource in the resource database, use the native client to simulate the target resource as the response data of the resource acquisition request, and send the response data to the H5 page.

[0025] Optionally, after the step of directly forwarding the ordinary network request to the target server, the method further includes:

[0026] Obtain the normal response data of the target server to the normal network request, and send the normal response data of the target server to the H5 page.

[0027] Optionally, the step of caching the target resource to the resource database includes:

[0028] The resource database includes a root folder generated based on the H5 webpage access address. Within the root folder, the target resource is cached in the corresponding file using the address or unique identifier of the target resource as the file name.

[0029] Furthermore, to achieve the above objectives, the present invention also provides an adaptive H5 resource loading device, the adaptive H5 resource loading device comprising:

[0030] The request listening module listens for network requests sent by the H5 page and identifies the type of the network request.

[0031] The request forwarding module, if the type of the network request is a normal network request, will directly forward the normal network request to the target server;

[0032] The resource acquisition module, if the network request is a resource acquisition request, uses the native client to acquire the target resource corresponding to the resource acquisition request, caches the target resource in the resource database, uses the native client to simulate the target resource as the response data of the resource acquisition request, and sends the response data to the H5 page.

[0033] Furthermore, to achieve the above objectives, the present invention also provides an adaptive H5 resource loading device, which includes a memory, a processor, and an adaptive H5 resource loading program stored in the memory and executable on the processor. When the adaptive H5 resource loading program is executed by the processor, it implements the steps of the adaptive H5 resource loading method as described above.

[0034] Furthermore, to achieve the above objectives, the present invention also provides a storage medium storing an adaptive H5 resource loader, wherein the adaptive H5 resource loader, when executed by a processor, implements the steps of the adaptive H5 resource loading method as described above.

[0035] This invention relates to an adaptive H5 resource loading method. It listens for network requests from H5 pages and identifies the type of each request. If the request is a normal request, it is forwarded directly to the target server without interception. If the request is a resource retrieval request, it is intercepted, the target resource corresponding to the request is retrieved using the native client, and cached in a resource database. Simultaneously, the native client simulates the resource retrieval request's response data and sends it to the H5 page. This invention improves resource loading efficiency by using the native client to handle resource requests and optimizes memory usage through an intelligent cache management mechanism, thereby solving the problems of slow loading speed, high memory consumption, and poor cache management in existing technologies. Attached Figure Description

[0036] Figure 1 This is a schematic diagram of the hardware operating environment of the device involved in the embodiment of the adaptive H5 resource loading device of the present invention;

[0037] Figure 2 This is a flowchart illustrating the first embodiment of the adaptive H5 resource loading method of the present invention;

[0038] Figure 3 This is a schematic diagram of the functional modules of a preferred embodiment of the adaptive H5 resource loading device of the present invention.

[0039] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0040] It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention.

[0041] It's worth noting that with the rapid development of the mobile internet, mobile applications (Apps) have become an indispensable part of people's daily lives. Among these applications, HTML5 technology is widely used due to its cross-platform compatibility and powerful expressive capabilities. However, in practical applications, the resource loading efficiency and memory management of HTML5 pages have always been pressing issues that need to be addressed.

[0042] H5 pages are often developed and displayed to more conveniently and quickly showcase the latest content and layout, such as event pages and product introductions. However, on mobile devices, due to network conditions and device performance limitations, H5 pages often face the following problems when loading resources:

[0043] Slow loading speed: The network environment of mobile devices is relatively unstable, which leads to slow loading speed of H5 page resources and affects user experience.

[0044] High memory usage: Mobile devices have limited memory resources, and loading a large number of resources will lead to high memory usage, thus affecting the performance of applications.

[0045] Poor cache management: Traditional browser caching mechanisms cannot fully utilize the characteristics of mobile devices, resulting in low cache hit rates and repeated downloads of resources.

[0046] To address these issues, existing technologies have proposed several optimization solutions. These include compressing resource files, using CDNs (Content Delivery Networks) to accelerate resource loading, and improving browser cache utilization. However, these methods still have limitations and cannot fundamentally solve the problems of low resource loading efficiency and poor memory management in mobile applications.

[0047] To address the aforementioned shortcomings, this invention provides an adaptive H5 resource loading device, referring to... Figure 1 , Figure 1 This is a schematic diagram of the hardware operating environment of the device involved in the embodiment of the adaptive H5 resource loading device of the present invention.

[0048] like Figure 1 As shown, the adaptive H5 resource loading device may include: a processor 1001, such as a CPU; a communication bus 1002; a user interface 1003; a network interface 1004; and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen and an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be high-speed RAM or stable non-volatile memory, such as a disk drive. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0049] Those skilled in the art will understand that Figure 1The hardware structure of the adaptive H5 resource loading device shown in the figure does not constitute a limitation on the adaptive H5 resource loading device. It may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0050] like Figure 1 As shown, the memory 1005, as a storage medium, may include an operating system, a network communication module, a user interface module, and an adaptive H5 resource loader. The operating system is a program that manages and controls the adaptive H5 resource loading device and software resources, supporting the operation of the network communication module, the user interface module, the adaptive H5 resource loader, and other programs or software. The network communication module manages and controls the network interface 1004; the user interface module manages and controls the user interface 1003.

[0051] exist Figure 1 In the hardware structure of the adaptive H5 resource loading device shown, the network interface 1004 is mainly used to connect to the backend server and communicate with it; the user interface 1003 is mainly used to connect to the client and communicate with it; the processor 1001 can call the adaptive H5 resource loading program stored in the memory 1005 and perform the following operations:

[0052] Listen for network requests sent by H5 pages and identify the type of the network requests;

[0053] If the network request is a normal network request, the normal network request will be forwarded directly to the target server;

[0054] If the network request is a resource acquisition request, the native client obtains the target resource corresponding to the resource acquisition request, caches the target resource in the resource database, uses the native client to simulate the target resource as the response data of the resource acquisition request, and sends the response data to the H5 page.

[0055] Furthermore, the step of monitoring network requests sent by the H5 page includes:

[0056] Use a webview container, network proxy, network hook, or network library interceptor to listen for network requests sent by the H5 page.

[0057] Furthermore, after the step of obtaining the target resource corresponding to the resource acquisition request using the native end, the method further includes:

[0058] If the target resource is a video resource that can be played online, the native client will synchronously send the video segment data stream of the video resource to the H5 page, and display the target resource through the H5 page.

[0059] Furthermore, after the step of caching the target resource to the resource database, the method further includes:

[0060] Monitor the remaining memory of the device where the resource database is located;

[0061] If the remaining memory is less than a preset value, perform a cache cleanup operation on the resource database;

[0062] If the remaining memory is not less than the preset value, the cached resources in the resource database that have reached the preset cache duration are cleaned up.

[0063] Furthermore, after the step of caching the target resource to the resource database, the method further includes:

[0064] When the H5 page sends another resource retrieval request, the data resource library is retrieved through the native terminal.

[0065] If the data resource library contains local cached resources corresponding to the resource acquisition request, the cached resources will be sent to the H5 page.

[0066] If the data resource library does not contain a local cached resource corresponding to the resource acquisition request, the following steps are performed: use the native client to obtain the target resource corresponding to the resource acquisition request, cache the target resource in the resource database, use the native client to simulate the target resource as the response data of the resource acquisition request, and send the response data to the H5 page.

[0067] Furthermore, after the step of directly forwarding the ordinary network request to the target server, the method further includes:

[0068] Obtain the normal response data of the target server to the normal network request, and send the normal response data of the target server to the H5 page.

[0069] Furthermore, the step of caching the target resource to the resource database includes:

[0070] The resource database includes a root folder generated based on the H5 webpage access address. Within the root folder, the target resource is cached in the corresponding file using the address or unique identifier of the target resource as the file name.

[0071] The specific implementation of the adaptive H5 resource loading device of the present invention is basically the same as the embodiments of the adaptive H5 resource loading method described below, and will not be repeated here.

[0072] The present invention also provides an adaptive H5 resource loading method based on the above-mentioned adaptive H5 resource loading device.

[0073] Reference Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of the adaptive H5 resource loading method of the present invention.

[0074] This invention provides an embodiment of an adaptive H5 resource loading method. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0075] In various embodiments of the adaptive H5 resource loading method, the execution entity is the adaptive H5 resource loading device.

[0076] The adaptive H5 resource loading method is applied to an adaptive H5 resource loading device, and the adaptive H5 resource loading method includes:

[0077] Step S10: Listen for network requests sent by the H5 page and identify the type of the network request;

[0078] With the rapid development of the mobile internet, mobile applications (Apps) have become an indispensable part of people's daily lives. Among these applications, HTML5 technology is widely used due to its cross-platform compatibility and powerful expressive capabilities. However, in practical applications, the resource loading efficiency and memory management of HTML5 pages have always been problems that urgently need to be solved.

[0079] H5 pages are often developed and displayed to more conveniently and quickly showcase the latest content and layout, such as event pages and product introductions. However, on mobile devices, due to network conditions and device performance limitations, H5 pages often face the following problems when loading resources:

[0080] Slow loading speed: The network environment of mobile devices is relatively unstable, which leads to slow loading speed of H5 page resources and affects user experience.

[0081] High memory usage: Mobile devices have limited memory resources, and loading a large number of resources will lead to high memory usage, thus affecting the performance of applications.

[0082] Poor cache management: Traditional browser caching mechanisms cannot fully utilize the characteristics of mobile devices, resulting in low cache hit rates and repeated downloads of resources.

[0083] To address these issues, existing technologies have proposed several optimization solutions. These include compressing resource files, using CDNs (Content Delivery Networks) to accelerate resource loading, and improving browser cache utilization. However, these methods still have limitations and cannot fundamentally solve the problems of low resource loading efficiency and poor memory management in mobile applications.

[0084] In this embodiment, network requests sent by H5 pages are monitored, and the type of network request is identified.

[0085] For example, an H5 page in a news application needs to load a large number of images and video resources. The client listens for all network requests made by the H5 page through a webview container. When the H5 page makes a network request, the client can identify the type of request.

[0086] Example Explanation: When a user clicks on an article in a news application, the client captures all network requests through the webview container, forwards the HTML and CSS files to the server, and returns the response data to the H5 page. Simultaneously, when the H5 page requests image resources, the client uses the native implementation to download and cache the images.

[0087] The network request types include ordinary network requests and resource retrieval requests. These are different types of requests issued by an H5 page when loading content. The processing methods for these two types of requests differ in this invention. The following is one explanation of the network request types:

[0088] Regular network requests refer to the requests made by an H5 page when loading HTML, CSS, JavaScript, and other files. These requests are necessary for loading and rendering the page structure and styles.

[0089] Example: When a user visits a webpage, the browser sends multiple regular network requests to retrieve the HTML document, CSS stylesheet, and JavaScript script.

[0090] The requested URL is, for example:

[0091] GET / index.html

[0092] GET / styles.css

[0093] GET / scripts.js.

[0094] Resource fetch requests: These are requests made by an H5 page when loading multimedia files such as images, videos, audio, and PDFs. These requests are typically used to load content or resources from the page.

[0095] Example: When a user browses a news article, the browser sends resource fetching requests to load the images and videos in the article.

[0096] The requested URL is, for example:

[0097] GET / images / pic123.jpg

[0098] GET / videos / video456.mp4.

[0099] Step S20: If the network request is a normal network request, forward the normal network request directly to the target server;

[0100] In this embodiment, if the network request is identified as a normal network request, the normal network request is not intercepted, and it is directly forwarded to the target server.

[0101] For example, in an online education application, an H5 page needs to load a large amount of courseware resources, including HTML documents, CSS stylesheets, and JavaScript scripts. For these ordinary network requests, the client forwards them directly to the target server for processing.

[0102] When a user opens a course page in an online education application, the page contains multiple HTML documents, CSS stylesheets, and JavaScript scripts. When a user opens a course page, the H5 page sends multiple regular network requests to retrieve the necessary HTML documents, CSS stylesheets, and JavaScript scripts.

[0103] The client listens for all network requests through a webview container, network proxy, or network hook technology.

[0104] After recognizing a normal network request, the client forwards these requests directly to the target server and obtains the server's response data.

[0105] The server's response data is returned to the H5 page, and the H5 page renders content based on the response data.

[0106] This processing method allows ordinary network requests to be directly forwarded to the target server for processing, ensuring that page structure and style resources such as HTML documents, CSS stylesheets, and JavaScript scripts are loaded and rendered in a timely manner. This improves the loading efficiency of H5 pages and optimizes the user experience.

[0107] Step S30: If the network request type is a resource acquisition request, use the native client to obtain the target resource corresponding to the resource acquisition request, cache the target resource in the resource database, use the native client to simulate the target resource as the response data of the resource acquisition request, and send the response data to the H5 page.

[0108] In this embodiment, when the H5 page needs to load multimedia resources such as images, videos, and PDFs, the client handles the resource retrieval request through the native side, ensuring efficient resource loading and caching management. All network requests issued by the H5 page are monitored using a webview container, network proxy, or network hook technology. The type of network request is identified to determine whether it is a resource retrieval request.

[0109] If the network request type is a resource retrieval request (such as multimedia files like images, videos, and PDFs), the client will hand the request over to the native side for processing.

[0110] The native application retrieves the corresponding resource files from the target server based on the resource retrieval request. This ensures the integrity and validity of the resource files.

[0111] The acquired resource files are cached in the resource database. The resource database includes a root folder generated based on the H5 webpage access address. Within the root folder, resource data is saved as files using the address or unique identifier of the target resource as the file name.

[0112] The native application simulates the response data of a resource retrieval request using cached target resource data. It ensures that the simulated response data format is consistent with the standard HTTP response data format, containing the correct content type and data.

[0113] The simulated response data is sent to the H5 page. After receiving the simulated response data, the H5 page displays the corresponding resource files normally.

[0114] This invention relates to an adaptive H5 resource loading method. It listens for network requests from H5 pages and identifies the type of each request. If the request is a normal request, it is forwarded directly to the target server without interception. If the request is a resource retrieval request, it is intercepted, the target resource corresponding to the request is retrieved using the native client, and cached in a resource database. Simultaneously, the native client simulates the resource retrieval request's response data and sends it to the H5 page. This invention improves resource loading efficiency by using the native client to handle resource requests and optimizes memory usage through an intelligent cache management mechanism, thereby solving the problems of slow loading speed, high memory consumption, and poor cache management in existing technologies.

[0115] Furthermore, a second embodiment of the adaptive H5 resource loading method of the present invention is proposed, wherein the step of listening to network requests sent by the H5 page in step S10 above includes:

[0116] Step a1: Use a webview container, network proxy, network hook, or network library interceptor to listen for network requests sent by the H5 page.

[0117] In this embodiment, to effectively handle network requests issued by H5 pages, especially resource acquisition requests, this embodiment provides a method to listen for these requests using a webview container, network proxy, network hook, or network library interceptor. Specific steps may include:

[0118] Using a WebView container for listening: In mobile applications, use a WebView container to load H5 pages. Configure the WebView container to intercept and listen for all network requests originating from the H5 page. Obtain detailed information about the network requests, including the request URL and request headers, through callback functions or event handling mechanisms.

[0119] Utilize a network proxy for monitoring: Set up a network proxy in your mobile application to forward all network requests through the proxy server. The network proxy captures all network requests from H5 pages and identifies the request type. It can obtain detailed request information, including the request method, request URL, request headers, and request body.

[0120] Network hook monitoring: Implement network hook technology in mobile applications to intercept the sending and receiving of network requests. Network hooks can obtain request information before a network request is sent and response information before the network response is returned. Hook functions handle network requests, identifying and classifying ordinary network requests and resource acquisition requests.

[0121] Use network library interceptors to monitor network requests: Manage network requests in mobile applications using network libraries (such as OkHttp, Retrofit, etc.). Configure network library interceptors to intercept and monitor all network requests originating from H5 pages. Interceptors can obtain detailed request information and process requests before they are sent or after the response is returned.

[0122] Example explanation:

[0123] Using a WebView container for listening: When a mobile application loads an H5 page, a WebView container is configured to listen for all network requests. When a user accesses content on the H5 page, the WebView container intercepts each request and retrieves the request information through a callback function. For ordinary network requests (such as HTML, CSS, and JavaScript), the WebView container directly forwards the request to the target server and retrieves the response data. For resource retrieval requests (such as images, videos, and PDFs), the WebView container hands the request over to the native side for processing, downloading the resource and caching it.

[0124] Utilizing a network proxy for monitoring: The mobile application sets up a network proxy to forward all network requests through the proxy server. The network proxy server captures and analyzes all network requests, identifying the request type. For ordinary network requests, the proxy server directly forwards the request to the target server and returns the response data to the client. For resource retrieval requests, the proxy server instructs the client to download the resource using the native client and caches the resource data in a local database.

[0125] Using network hooks for monitoring: Mobile applications implement network hook technology to intercept request information before network requests are sent. When an H5 page sends a network request, the network hook captures the request data and identifies the request type. For ordinary network requests, the network hook allows the request to proceed directly to the target server. For resource retrieval requests, the network hook notifies the native side to process the request, download the resource, and cache it.

[0126] Using network library interceptors for listening: Mobile applications use network libraries (such as OkHttp and Retrofit) to manage network requests and configure interceptors. The interceptors intercept all network requests originating from H5 pages and obtain request information. For ordinary network requests, the interceptors forward the request to the target server and return response data. For resource retrieval requests, the interceptors call the native side to download the resource and cache the resource data in a local database.

[0127] This embodiment captures and processes network requests by utilizing a webview container, network proxy, network hooks, or network library interceptors. This effectively distinguishes between ordinary network requests and resource retrieval requests, ensuring fast resource loading and cache management, and improving user experience.

[0128] Furthermore, a third embodiment of the adaptive H5 resource loading method of the present invention is proposed. In step S30 above, after the step of obtaining the target resource corresponding to the resource acquisition request using the native end, the method further includes:

[0129] Step b1: If the target resource is a video resource that can be played online, the native client synchronously sends the video segment data stream of the video resource to the H5 page, and displays the target resource through the H5 page.

[0130] In this embodiment, when processing resource acquisition requests from an H5 page, if the requested target resource is a video resource that can be played online, the native side needs to synchronously send the video segment data stream to the H5 page and display the video resource through the H5 page. Specific steps may include:

[0131] Identify resource retrieval requests: Listen for and capture network requests sent by H5 pages, and identify resource retrieval requests. Determine the type of the target resource in the request, and determine whether it is a video resource that can be played online.

[0132] Using the native client to retrieve the target resource: The native client retrieves the video resource from the target server based on the resource retrieval request. It downloads the video resource and ensures the integrity and validity of the video data.

[0133] Handling video resources: If the target resource is a video resource that can be played online, the native side processes the video resource into a video segment data stream. The video segment data stream can be downloaded in segments as needed to reduce loading time and memory usage.

[0134] Synchronously send video data stream to H5 page: The native side synchronously sends the processed video segment data stream to the H5 page. This ensures the stability and continuity of data stream transmission, resulting in smooth video playback.

[0135] Displaying video resources via H5 pages: After receiving the video segment data stream, the H5 page can use its built-in HTML5 video player to display the video resources. The video player performs real-time playback and buffering based on the received data stream to ensure a smooth playback experience.

[0136] This embodiment utilizes the native platform to acquire video resources and process them into video segment data streams, which are then synchronously sent to the H5 page in real time for display via an HTML5 video player. This ensures fast loading and smooth playback of video resources, enhancing the user experience.

[0137] Furthermore, a fourth embodiment of the adaptive H5 resource loading method of the present invention is proposed. In step S30 above, after the step of caching the target resource to the resource database, the method further includes:

[0138] Step c1: Monitor the remaining memory of the device where the resource database is located;

[0139] Step c2: If the remaining memory is less than a preset value, perform a cache cleanup operation on the resource database;

[0140] Step c3: If the remaining memory is not less than the preset value, clean up the cached resources in the resource database that have reached the preset time.

[0141] In this embodiment, in addition to caching the target resource to the resource database, it is also necessary to monitor the remaining memory of the device where the resource database is located and perform cached resource cleanup operations based on the memory status. Specific steps may include:

[0142] Cache target resources: When processing resource retrieval requests, the retrieved target resources are cached in the resource database. The resource database includes a root folder generated based on the H5 webpage access address. Within the root folder, resource data is saved as files using the address or unique identifier of the target resource as the file name.

[0143] Monitor device remaining memory: The client periodically or in real-time monitors the remaining memory of the device hosting the resource database. This monitors the system's memory usage and retrieves the current remaining memory value.

[0144] Cache cleanup when memory is low: If the device's remaining memory is detected to be less than a preset value (e.g., 100MB), a cache cleanup operation is triggered. This cleans up cached resources in the resource database to free up memory. Cleanup strategies may include deleting the least used resources and deleting resources that consume a large amount of memory by size.

[0145] Periodic cleanup when memory is sufficient: If the device's remaining memory is not less than a preset value, perform a periodic cache cleanup operation. Clean up cached resources in the resource database that have reached a preset cache duration. Cleanup strategies may include deleting resources that have exceeded a certain cache time, deleting infrequently used resources based on access frequency, etc.

[0146] Example explanation:

[0147] In a news application, when a user browses a news article, the H5 page sends a request to retrieve image resources. The client downloads the image resources from the native side and caches them in the resource database.

[0148] The client periodically or in real-time monitors the device's remaining memory to obtain the current memory usage. For example, it monitors memory usage every minute to obtain the remaining memory value.

[0149] If the device's remaining memory is detected to be less than a preset value (e.g., 100MB), a cache cleanup operation is triggered. The cleanup strategy involves deleting the least used resource from the resource database. For example, deleting the oldest cached file, image1.jpg, to free up memory space.

[0150] If the device's remaining memory is detected to be greater than or equal to a preset value (e.g., 100MB), a periodic cache cleanup operation is performed. Cleanup strategy: Delete resources that have been cached for more than a certain period (e.g., 30 days). For example, delete image2.jpg that has been cached for more than 30 days to maintain cache validity.

[0151] This embodiment, after caching the target resource, periodically or in real-time monitors the device's remaining memory and performs cached resource cleanup operations based on the memory status. This ensures the rational use of device memory, avoids impacting system performance due to excessive memory consumption by cached resources, maintains the effectiveness of cached resources, and improves user experience.

[0152] Furthermore, a fifth embodiment of the adaptive H5 resource loading method of the present invention is proposed, wherein, after the step of caching the target resource to the resource database in step S30 above, the method further includes:

[0153] Step d1: When the H5 page sends another resource acquisition request, the data resource library is retrieved through the native terminal;

[0154] Step d2: If the data resource library contains local cached resources corresponding to the resource acquisition request, send the cached resources to the H5 page.

[0155] Step d3: If the data resource library does not contain local cached resources corresponding to the resource acquisition request, perform the following steps: use the native client to obtain the target resource corresponding to the resource acquisition request, cache the target resource in the resource database, use the native client to simulate the target resource as the response data of the resource acquisition request, and send the response data to the H5 page.

[0156] In this embodiment, to improve resource loading efficiency when processing resource retrieval requests from H5 pages, this invention provides a method for handling duplicate resource requests by retrieving data resource libraries from the native side. When a resource retrieval request is detected again from an H5 page, the local cached resources are first checked, and a decision is made based on the cache status whether to re-retrieve the target resource. Specific steps may include:

[0157] Cache target resources: When processing resource retrieval requests, the retrieved target resources are cached in the resource database. The resource database includes a root folder generated based on the H5 webpage access address. Within the root folder, resource data is saved as files using the address or unique identifier of the target resource as the file name.

[0158] Listen for duplicate resource fetch requests: When the H5 page sends a resource fetch request again, the client captures the request through the webview container, network proxy, or network hook technology. The request's URL and resource identifier are checked to determine if it is a cached resource request.

[0159] Retrieving the Data Resource Repository: The native side searches the data resource repository based on the resource retrieval request. It checks whether the data resource repository contains a locally cached resource corresponding to the resource retrieval request.

[0160] Handling cached resources: If the database contains corresponding local cached resources, send the cached resources directly to the H5 page. Utilize the native side to simulate the cached resources as response data for a resource retrieval request, ensuring the response data format is consistent with the standard HTTP response data format.

[0161] Re-fetch the target resource: If the corresponding local cached resource is not contained in the resource database, retrieve the target resource corresponding to the resource retrieval request using the native side. Cache the retrieved target resource in the resource database and simulate the response data of the resource retrieval request, then send it to the H5 page.

[0162] In this embodiment, when a resource retrieval request is detected again from the H5 page, the system first checks the local cached resources in the database. If cached resources are found, they are directly returned to the H5 page; otherwise, the target resources are retrieved again and cached. This method improves resource loading efficiency, reduces redundant downloads, and optimizes the user experience.

[0163] Furthermore, a sixth embodiment of the adaptive H5 resource loading method of the present invention is proposed, which, after step S20 above, further includes:

[0164] Step e1: Obtain the normal response data of the target server to the normal network request, and send the normal response data of the target server to the H5 page.

[0165] In this embodiment, when processing ordinary network requests for H5 pages, a method is provided to directly forward ordinary network requests to the target server and obtain its response data. Specific steps may include:

[0166] Listen for network requests: Use the webview container, network proxy, or network hook technology to listen for all network requests made by the H5 page. Identify the type of network request and determine whether it is a normal network request.

[0167] Forwarding Regular Network Requests: If a request is identified as a regular network request (such as an HTML, CSS, or JavaScript file request), it is forwarded directly to the target server. The integrity of the request data is ensured, including request headers, request methods, and request parameters. The target server refers to the server that receives and processes network requests from H5 pages, and also the server hosting the website, application, or service, responsible for responding to requests from clients (such as mobile applications or browsers) and providing corresponding data and resources.

[0168] Retrieve target server response data: Obtain the target server's response data to a regular network request. Response data includes the response status code, response headers, and response body.

[0169] Sending response data to the H5 page: This involves sending the standard response data returned by the target server to the H5 page. This ensures the integrity and consistency of the response data, enabling the H5 page to correctly parse and render the content.

[0170] Example explanation:

[0171] In a news application, when a user browses a news article, the H5 page sends requests for HTML, CSS, and JavaScript files. The client captures these network requests through a webview container and identifies them as normal network requests. The client forwards the captured HTML, CSS, and JavaScript requests directly to the target server www.newsapp.com. The integrity of the request is ensured, including request headers, request methods, and request parameters. Upon receiving the request, the target server returns response data, including a response status code, response headers, and a response body. The client then sends the response data from the target server to the H5 page. The H5 page renders the response data to display the complete news article content.

[0172] This embodiment, after capturing ordinary network requests from the H5 page, directly forwards the requests to the target server and retrieves the response data, sending it to the H5 page. This method ensures fast processing and response of ordinary network requests, improves the loading speed and rendering effect of H5 page content, and optimizes the user experience.

[0173] Furthermore, a seventh embodiment of the adaptive H5 resource loading method of the present invention is proposed, wherein the step S30 above, the step of caching the target resource to the resource database, includes:

[0174] Step f1: The resource database includes a root folder generated based on the H5 webpage access address. Within the root folder, the target resource is cached in the corresponding file using the address or unique identifier of the target resource as the file name.

[0175] In this embodiment, to effectively manage and store target resources obtained from H5 pages, a method for caching target resources to a resource database is provided. Specific steps may include:

[0176] Generate a root folder based on the H5 webpage's access address: When an H5 page sends a resource retrieval request, the client obtains the requested URL. A corresponding root folder is generated based on the H5 webpage's access address (e.g., domain name and path) to store all resources related to that webpage.

[0177] Generate a unique identifier: Generate a unique identifier for each target resource, typically using the resource's address (URL) or other unique information (such as a hash value) as the identifier.

[0178] Cache target resources to corresponding files: Within the root folder, save the resource data as a file using the target resource's address or unique identifier as the filename. Ensure that each resource file is stored in its corresponding folder for easy retrieval and management.

[0179] Example explanation:

[0180] In a news app, when a user browses a news article, the H5 page sends a request to retrieve an image resource. The requested URL is 'https: / / www.newsapp.com / articles / image1.jpg'.

[0181] The client generates a root folder ' / cache / newsapp.com / articles / ' based on 'https: / / www.newsapp.com / articles / '.

[0182] The target resource's address is 'image1.jpg'. The client uses the resource address 'image1.jpg' as the filename.

[0183] The client saves the downloaded image resource to ' / cache / newsapp.com / articles / image1.jpg'.

[0184] If there are multiple resource files, such as 'image2.jpg' and 'image3.jpg', save them to:

[0185] ' / cache / newsapp.com / articles / image2.jpg'

[0186] ' / cache / newsapp.com / articles / image3.jpg'.

[0187] This embodiment generates a root folder based on the H5 webpage access address and saves the resource data as a file using the address or unique identifier of the target resource. This method can effectively organize and manage cached resources, facilitate quick retrieval and use, and improve resource loading efficiency.

[0188] The present invention also provides an adaptive H5 resource loading device.

[0189] Reference Figure 3 , Figure 3 This is a functional module diagram of a first embodiment of the adaptive H5 resource loading device of the present invention. The adaptive H5 resource loading device includes:

[0190] The request listening module listens for network requests sent by the H5 page and identifies the type of the network request.

[0191] The request forwarding module, if the type of the network request is a normal network request, will directly forward the normal network request to the target server;

[0192] The resource acquisition module, if the network request type is a resource acquisition request, uses the native client to obtain the target resource corresponding to the resource acquisition request, caches the target resource in the resource database, uses the native client to simulate the target resource as the response data of the resource acquisition request, and sends the response data to the H5 page.

[0193] Furthermore, embodiments of the present invention also propose a storage medium.

[0194] An adaptive H5 resource loader is stored on the storage medium. When the adaptive H5 resource loader is executed by the processor, it implements the steps of the adaptive H5 resource loading method as described above.

[0195] The specific implementation of the storage medium of the present invention is basically the same as the embodiments of the above-described adaptive H5 resource loading method, and will not be repeated here.

[0196] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many modifications under the guidance of the present invention without departing from the spirit and scope of the claims. All equivalent structural or procedural transformations made using the content of the present invention specification and drawings, or direct or indirect applications in other related technical fields, are within the protection scope of the present invention.

[0197] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0198] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. If the function is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.

[0199] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0200] The above descriptions are merely various embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. An adaptive H5 resource loading method, characterized in that: The adaptive H5 resource loading method comprises the following steps: Monitor the network requests sent by the H5 page and identify the type of the network requests; If the type of the network request is a common network request, forwarding the common network request directly to the target server; If the type of the network request is a resource acquisition request, the target resource corresponding to the resource acquisition request is acquired using the native end, the target resource is cached in a resource database, the target resource is simulated into response data of the resource acquisition request using the native end, and the response data is sent to the H5 page.

2. The adaptive H5 resource loading method according to claim 1, characterized in that: The step of monitoring the network request issued by the H5 page includes: The webview container, network proxy, network hook, or network library interceptor is used to monitor the network request issued by the H5 page.

3. The adaptive H5 resource loading method as claimed in claim 1, characterized in that: After the step of using the native end to obtain the target resource corresponding to the resource acquisition request, the method further includes: If the target resource is a video resource that can be played online, the native end synchronously sends the video segment data stream of the video resource to the H5 page, and displays the target resource through the H5 page.

4. The adaptive H5 resource loading method according to claim 1, characterized in that: After the step of caching the target resource in the resource database, the method further includes: Monitor the remaining memory of the device where the resource database is located; If the remaining memory is less than a preset value, a cache cleaning operation is performed on the resource database; If the remaining memory is not less than the preset value, cache resources in the resource database whose cache time reaches the preset time length are cleared.

5. The adaptive H5 resource loading method according to claim 1, characterized in that: After the step of caching the target resource in the resource database, the method further includes: When monitoring that the H5 page sends a resource acquisition request again, the data resource library is retrieved through the native end; If the data resource library contains a local cache resource corresponding to the resource acquisition request, the cache resource is sent to the H5 page; If the data resource library does not contain a local cache resource corresponding to the resource acquisition request, execute the following steps: use the native end to obtain the target resource corresponding to the resource acquisition request, cache the target resource to the resource database, use the native end to simulate the target resource into the response data of the resource acquisition request, and send the response data to the H5 page.

6. The adaptive H5 resource loading method according to claim 1, characterized in that: After the step of directly forwarding the common network request to the target server, the method further includes: Obtain the target server's common response data to the common network request, and send the target server's common response data to the H5 page.

7. The adaptive H5 resource loading method according to claim 1, characterized in that: The step of caching the target resource into a resource database comprises: The resource database includes a root folder generated according to the H5 web page access address. In the root folder, the target resource is cached into a corresponding file using the address or unique identifier of the target resource as the file name.

8. An adaptive H5 resource loading device, characterized in that: The adaptive H5 resource loading device comprises: A request monitoring module monitors network requests sent by the H5 page and identifies the type of the network request; A request forwarding module, if the type of the network request is a common network request, forwards the common network request directly to the target server; The resource acquisition module uses the native end to obtain the target resource corresponding to the resource acquisition request if the type of the network request is a resource acquisition request, caches the target resource to the resource database, uses the native end to simulate the target resource into the response data of the resource acquisition request, and sends the response data to the H5 page.

9. An adaptive H5 resource loading device, characterized in that: The adaptive H5 resource loading device includes a memory, a processor, and an adaptive H5 resource loading program stored in the memory and executable on the processor. When the adaptive H5 resource loading program is executed by the processor, the steps of the adaptive H5 resource loading method according to any one of claims 1 to 7 are implemented.

10. A storage medium, characterized in that: An adaptive H5 resource loading program is stored on the storage medium, and when the adaptive H5 resource loading program is executed by the processor, the steps of the adaptive H5 resource loading method according to any one of claims 1 to 7 are implemented.