H5 loading acceleration method and system

By parallel processing of H5 static resource download and service request configuration and sending, combined with preloading and intelligent cache, the problem of long loading time of H5 pages is solved, fast loading and efficient operation is achieved, and user experience and application responsiveness are improved.

CN118964765APending Publication Date: 2024-11-15BEIJING BAILONG MAYUN TECH CO LTD
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411159186.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

The H5 page loading time is long, especially due to loading delays caused by large JavaScript files, large numbers of images or complex CSS, which affects the user experience.

Method used

By parallel processing of H5 static resource download and service request configuration and sending, combining preloading strategies and intelligent caching mechanisms, resource mounts and interactions are optimized, and configuration dynamic updates and data fault tolerance are adopted to reduce loading time and improve user experience.

Benefits of technology

It significantly shortens the loading time of H5 pages, improves user experience, reduces dependence on the network, reduces server load, improves resource reuse rate and loading efficiency, and ensures application responsiveness and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964765A_ABST
    Figure CN118964765A_ABST
Patent Text Reader

Abstract

The invention discloses an H5 loading acceleration method and system. S1000, reading an H5 page structure: calling Ajax to examine an H5 page source code, and identifying a service request trigger point embedded in the page by using a fetch request; s1001, extracting service request information; S10010, identifying a request URL (Uniform Resource Locator): determining a destination address (URL) of each service request, wherein the destination address (URL) comprises a basic path or a query parameter; the invention relates to the technical field of internet information. According to the invention, through parallel processing of the service request and static resource downloading (S100 and S101) and optimization of the caching strategy (S201), the time of resource loading and data processing is reduced, so that the loading time of the H5 page is remarkably shortened, and the user experience is improved. The intelligent cache logic and configuration dynamics (S101 and S201) ensure that the frequently accessed resources can be quickly read from the cache, the dependence on the network is reduced, the load of the server is reduced, and the reuse rate and the loading efficiency of the resources are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Internet information technology, specifically to the field of hypertext markup language technology, and in particular to a method and system for accelerating H5 loading. Background Art

[0002] H5, or HTML5, is the fifth version of Hypertext Markup Language (HTML). It is an important standard in the field of Internet information technology and has greatly promoted the expressiveness and interactivity of web content. HTML5 introduces many new features, including multimedia support (such as audio and video), graphics drawing capabilities (Canvas), offline storage (localStorage and IndexedDB), and improved form processing and input types, allowing developers to create richer and more dynamic web applications, and even develop web applications that are close to the native application experience. The process of loading H5 on the client can be roughly divided into the following steps (see Figure 1 The right half of ):

[0003] S1. Initialize WebView: In native applications, when an H5 page needs to be loaded, a WebView component will be initialized first. WebView is equivalent to an embedded browser, responsible for parsing and rendering H5 pages.

[0004] S2. Send network request: WebView initiates an HTTP / HTTPS request to the server, requesting the HTML file of the H5 page.

[0005] S3. Load resource files: After the HTML document is loaded, WebView will continue to load external resources such as CSS style sheets, JavaScript scripts, and images referenced in the document.

[0006] S4, parsing and rendering: WebView parses HTML and CSS, builds the DOM tree and CSSOM tree, and finally merges them into a rendering tree, and renders the page based on it. At the same time, JavaScript will be executed, which may affect the DOM structure and style. This process may be iterated multiple times.

[0007] S5. Interaction preparation: Once the page completes initial rendering, it can start processing user interaction events. At the same time, the H5 page can communicate with the native application in both directions through JavaScript, calling the native API or being called by the native application.

[0008] Although the performance of current client devices has generally improved, large JavaScript files, a large number of images or complex CSS will significantly increase loading time. In addition, JavaScript parsing and execution, especially for complex single-page applications, will consume a lot of time. The reasons are classified as follows:

[0009] (1) The triggering of business requests depends on the construction of JSBridge (involving interaction with native functions);

[0010] (2) The construction of JSBridge depends on the loading progress of static resources;

[0011] (3) The loading of static resources depends on the network and can only be loaded after being downloaded;

[0012] (4) When the page is opened, only static resource requests are triggered, while business requests are triggered after that.

[0013] Users may need to wait for all necessary resources to load before seeing the actual content, that is, a "white screen" will appear when we open certain web pages, which has a great impact on the user experience.

[0014] To this end, the present invention proposes a method and system for accelerating H5 loading. Summary of the invention

[0015] In view of this, the present invention hopes to provide a method and system for accelerating H5 loading, so as to solve or alleviate the technical problems existing in the prior art, that is, how to load H5 files faster, and at least provide a beneficial option for this; the technical solution of the present invention is implemented as follows:

[0016] First, a method to speed up H5 loading:

[0017] 1. Overview:

[0018] This solution aims to solve the above technical problems. By processing H5 static resource downloads and business request configuration sending in parallel, fine-tuning request parameters and combining preloading strategies with intelligent caching mechanisms, and using jsBridge to optimize resource mounting and interaction, it aims to fundamentally reduce loading time and improve user experience. At the same time, the solution incorporates configuration dynamic update and data fault-tolerant processing logic to ensure flexibility, stability and data security. It is a comprehensive optimization strategy for efficient loading and operation of modern H5 applications.

[0019] (II) Technical solution:

[0020] To achieve the above technical objectives, this solution needs to execute the following steps S1 to S3.

[0021] 2.1 Step S1, triggering a service request:

[0022] Download H5 static resources, select specified configuration, form request parameters and coverage data, and send a service request. Specifically, it includes the following steps S100 to S101 implemented in parallel.

[0023] 2.1.1 Step S100, H5 static resource download request:

[0024] Extract the business request of the H5 page and encapsulate the data of the extracted business request according to the protocol. The implementation method includes:

[0025] S1000, read the H5 page structure: call Ajax to review the H5 page source code, and use the fetch request to identify the business request trigger point embedded in the page;

[0026] S1001, extracting business request information:

[0027] S10010, request URL identification: determine the destination address (URL) of each service request, including the basic path or query parameters;

[0028] S10011, Request type confirmation: record the request method type, including GET or POST, etc.;

[0029] S10012, Request header and parameter extraction: Extract the header information of each request, such as Authorization or Content-Type, and distinguish between public parameters, business parameters, and dynamic parameters;

[0030] S10013, build protocol, including:

[0031] S100130, Common Protocol Section: defines the format and location of common parameters, including authentication information and device identification;

[0032] S100131, Business logic coding: assign identifiers or instruction codes to different business scenarios to facilitate identification and processing by the server;

[0033] S100132, dynamic parameter slot: reserved space for inserting dynamic parameters that change according to different situations;

[0034] S10014, Data encapsulation and protocol application: For each extracted service request, integrate the public parameters, service parameters and dynamic parameters in the format specified by the protocol; if necessary, encrypt or sign the data to ensure the security of data transmission;

[0035] S10015, Preprocessing and optimization: Enable compression algorithm to reduce data volume; use encapsulated protocol data to send requests to the server through XMLHttpRequest network request library or fetch API network request library.

[0036] 2.1.2 Step S101, select the specified configuration and send a service request:

[0037] Executed simultaneously with step S100; reading the configuration protocol of the pre-request and the cache read protocol of the pre-request to form a data packet; wherein the formation of the data packet includes:

[0038] 1) Configuration protocol: Extract the URL, HTTP method and standardized request header information corresponding to the business request from the configuration file. The classified extracted request parameters include:

[0039] 1.1) Public parameters: user authentication information, language settings;

[0040] 1.2) Business parameters: identify and organize the parameters of the current business;

[0041] 1.3) Equipment information parameters;

[0042] 2) Cache read protocol: Expand the configured request parameters to cover all H5 pages and form coverage data, including:

[0043] 2.1) Extended configuration parameters: Generate or adjust request parameters;

[0044] 2.2) Coverage data: Generate a comprehensive set of coverage data for request parameters to ensure sufficient parameter support in any case;

[0045] 2.3) Cache logic integration: Before sending a request, query the local cache and decide whether to use cached data to respond to the request based on the cache read protocol, reducing unnecessary network communication.

[0046] Use the constructed data packet to send it to the server through the network interface. After receiving the server response, update the local cache.

[0047] 2.2 Step S2, loading:

[0048] Based on the data packet formed in step S1, a loading request is sent to the js resource to form return data. It includes the following steps S200-S201.

[0049] 2.2.1 Step S200, resource mounting:

[0050] After the loading request is confirmed, the jsBridge resource is mounted; the method flow is as follows:

[0051] S2000, load request confirmation: first confirm whether the data packet constructed in the S1 stage has been successfully sent to the server and received the server's preliminary response confirmation; if yes, activate step S2001, if not, send an error instruction to the server;

[0052] S2001, initializing jsBridge: the client application initializes or activates the jsBridge component.

[0053] jsBridge is a technology that allows JavaScript to interact with native application code (such as Android or iOS native code);

[0054] S2002, mount resources: mount the required JS resources (such as library files, frameworks or specific business logic scripts) to the current running environment, including but not limited to loading script files through URLs and registering callback functions to monitor loading status.

[0055] 2.2.2 Step S201, Cache:

[0056] Based on the data packet sent in step S101 (including request parameters and coverage data) and the jsBridge resource mounting in step S200, a request return command is sent and the return data is cached.

[0057] Update the configuration data of the previous request at the time specified by the client and save it to disk. Read the hit logic based on the returned data and supplement the fault tolerance logic of the returned data.

[0058] The method flow is as follows:

[0059] S2010, constructing a cache instruction: based on the data packet generated in S101 (including request parameters and coverage data), combined with the jsBridge resource mounted in S200, construct a cache storage instruction to instruct the system how to cache the response data to be received;

[0060] S2011, send request and cache data: execute the previously constructed loading request, obtain the actual js resource data, and store it in the client's cache system according to the cache strategy;

[0061] The cache strategy can use LRU (least recently used) strategy, TTL (time to live) strategy, etc. to optimize space utilization and data freshness;

[0062] S2012, update configuration data: at an appropriate time determined by the client (such as when the application is started, when the page is loaded, or when regular maintenance is performed), use the newly received or updated data to update the configuration information of the previous request, so that the updated data can be serialized and persistently stored on the disk;

[0063] S2013, cache hit logic: check the consistency of request parameters with existing cache entries, and verify the validity of cache data to determine whether subsequent requests can directly obtain data from the cache, and activate step S2014;

[0064] S2014, Fault-tolerance processing: When cached data is unavailable, the system should automatically fall back to the logic of re-initiating network requests to ensure business continuity.

[0065] 2.3 Step S3, read:

[0066] Based on the returned data of step S2, the cache is read and parsed, and the H5 data is refreshed and loaded.

[0067] 2.3.1 Step S300, cache reading:

[0068] Verify the existence of the cache item of the data cached in step S2, the data integrity, and whether it exceeds the preset validity period; if the cache is valid, read the previously stored H5 resource data from the local cache storage.

[0069] 2.3.2 Step S301, data analysis:

[0070] Parse the read H5 data, distinguish different resource types (such as HTML content, CSS styles or JS scripts) based on JSON or format parsing technology; create a sandbox environment for the JavaScript execution context, and map the parsed resources to specific loading tasks.

[0071] 2.3.3 Step S302, refresh and load:

[0072] If the H5 content already exists on the page, clean up or refresh the page first;

[0073] Adopt asynchronous loading mechanism, based on Promise technology or async / await technology to load the parsed HTML, CSS or JavaScript resources sequentially or in parallel, to ensure that resource loading does not block the user interface;

[0074] After loading is complete, JavaScript scripts are executed, CSS styles are applied, and finally the processed HTML content is rendered on the page. During this period, it is also necessary to handle abnormal situations where resource loading fails and provide a fallback or error prompt mechanism;

[0075] Once the H5 page is fully loaded and rendered, initialize the interactive logic on the page, including event monitoring and AJAX request processing, to ensure that the functions of the H5 application are fully available.

[0076] (III) Mechanism for solving technical problems:

[0077] In traditional processes, resource loading is usually linear, but by processing H5 static resource download requests and business request parameter configuration encapsulation in parallel in S100, and performing resource mounting and caching in S2, waiting time is greatly reduced and efficiency is improved. Through the cache reading protocol in S101 and the cache logic in S201, efficient caching and reuse of request data is achieved, reducing repeated requests to the server, and significantly improving loading speed, especially in weak network environments.

[0078] Dynamic configuration and parameter optimization: The configuration protocol in S101 not only optimizes the management of request parameters, but also allows flexible adjustment according to business needs, ensuring the efficiency and accuracy of requests. This dynamic configuration capability helps reduce unnecessary data transmission and speed up response.

[0079] Although traditional processes also load resources, this solution ensures the rapid presentation of core functions and improves user experience through more sophisticated control, such as prioritizing the loading of key resources or mounting jsBridge resources in S200. In addition, the optimization solution not only caches data in S201, but also updates the configuration and considers fault-tolerant logic, which can respond to changes more quickly during data processing and reduce loading failures caused by data problems.

[0080] The difference and effect from the traditional process are: through preloading and caching strategies, the dependence on the network is reduced, especially for frequently used resources and data, which can be loaded almost instantly. Parallel processing, dynamic configuration and priority allocation ensure that resources are loaded on demand and efficiently, avoiding blockage and waste in the resource loading process. By reducing the white screen time, quickly displaying interactive content, and responding to user operations in a timely manner, the overall fluency and response speed of the application are improved.

[0081] Second, a system to speed up H5 loading:

[0082] like Figure 2 As shown, the system includes a processor and a memory connected to the processor, wherein program instructions are stored in the memory. When the program instructions are executed by the processor, the processor executes the H5 loading speed-up method as described above.

[0083] Compared with the prior art, the present invention has the following beneficial effects:

[0084] 1. Improve loading speed: The present invention reduces the time of resource loading and data processing by processing business requests and static resource downloads in parallel (S100 and S101), as well as optimizing the cache strategy (S201), thereby significantly shortening the loading time of the H5 page and improving the user experience. Intelligent cache logic and dynamic configuration (S101 and S201) ensure that frequently accessed resources can be quickly read from the cache, reducing dependence on the network, while also reducing server load, and improving resource reuse and loading efficiency.

[0085] 2. Optimize data transmission and processing: The present invention ensures that only necessary data is transmitted, reduces data volume, speeds up data processing flow, and reduces network transmission costs through refined management of business requests (S100) and protocol encapsulation, as well as data preprocessing and optimization (S101). Through jsBridge resource mounting (S200) and efficient data reading logic (S3), fast initialization and rendering of H5 pages are ensured, so that applications can reach an interactive state faster, improve the responsiveness and stability of applications, and reduce user loss caused by loading delays.

[0086] 3. Enhanced adaptability and flexibility: The dynamic configuration and data management strategy (S101) of the present invention enables applications to better adapt to changes in different devices, network environments and user needs, improving the universality of applications and the convenience of long-term maintenance. The cache update mechanism, data persistence and fault-tolerant logic (S201) in this solution enhance the security of data and the robustness of applications, and can ensure the basic functions and service quality of applications even in the case of network instability or data anomalies. BRIEF DESCRIPTION OF THE DRAWINGS

[0087] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0088] Figure 1 It is a schematic diagram of the method flow of the present invention;

[0089] Figure 2 It is a schematic diagram of the system composition of the present invention. DETAILED DESCRIPTION

[0090] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below;

[0091] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0092] Embodiment 1: Figure 1 As shown, this embodiment discloses a method for accelerating H5 loading, and the implementation steps are as follows:

[0093] In this embodiment, regarding step S1, triggering a service request: downloading H5 static resources, selecting a specified configuration, forming request parameters and coverage data, and sending a service request, which specifically includes the following steps S100 to S101 implemented in parallel.

[0094] Specifically, step S100: parallel processing of H5 static resource download requests

[0095] Read H5 page structure (S1000): The HTML source code of the H5 page is asynchronously read using a fetch API or similar technology through a front-end script such as JavaScript. This step automatically scans the page to identify the triggering points of embedded Ajax calls or other asynchronous requests, preparing for subsequent request extraction.

[0096] Extracting business request information (S1001):

[0097] Request URL identification (S10010): Analyze the identified requests and extract the target URL of each business request to ensure that the request can correctly point to the server-side processing logic.

[0098] Request type confirmation (S10011): Determine the HTTP method (GET, POST, etc.) used for each request to classify the subsequent request construction.

[0099] Request header and parameter extraction (S10012): Record the request header information in detail, distinguish between fixed public parameters (such as authentication tokens), business-specific parameters, and dynamic parameters that change with user behavior or environment.

[0100] Construction protocol (S10013):

[0101] Public protocol part (S100130): Standardizes the organization of public parameters to facilitate rapid verification and processing.

[0102] Business logic coding (S100131): Assign specific codes or labels to different business scenarios to facilitate the server to quickly identify and execute the corresponding logic.

[0103] Dynamic parameter slot (S100132): A place in the protocol that allows parameter values ​​to be inserted dynamically when a request is sent.

[0104] Data encapsulation and protocol application (S10014): Integrate various parameters according to the protocol format, and optionally encrypt or sign the data to increase transmission security.

[0105] Preprocessing and optimization (S10015): Use compression algorithms such as GZIP to compress data volume, and send these optimized requests through XMLHttpRequest or Fetch API to reduce transmission time and bandwidth consumption.

[0106] Specifically, step S101, selecting a specified configuration and sending a service request: executing simultaneously with step S100; reading the configuration protocol of the pre-request and the cache read protocol of the pre-request to form a data packet; wherein the formation of the data packet includes:

[0107] Configuration protocol reading and application (S101-1): Dynamically read the configuration file, using the URL or HTTP method and standard request header information. This step ensures that each request follows the latest business rules and security standards. Automatically collect and package these parameters, reduce the tediousness of manual configuration, and speed up the request preparation process.

[0108] Cache read protocol and data packet construction (S101-2):

[0109] Extended configuration parameters and coverage data generation: Dynamically generate or adjust request parameters to ensure that all necessary parameters are fully considered, create a comprehensive parameter coverage set, and improve the success rate of requests.

[0110] Cache logic integration: Before a request is made, check the local cache to determine whether the cached response can be used directly, effectively reducing network requests and speeding up page loading.

[0111] Data packet sending and cache update: The constructed data packet is sent to the server through the network interface. After the server responds, the local cache is updated to ensure that similar requests in the future can obtain data from the cache faster, further improving loading speed and user experience.

[0112] It is understandable that in step S1, by processing static resource downloads and service requests in parallel and using caching strategies, the loading time of page resources is greatly reduced, improving the user experience. Standardized protocol construction and parameter management simplify the request processing process, reduce errors and omissions, and improve the success rate of requests. The use of data compression and caching strategies effectively reduces the amount of data transmission, reduces the burden on the server, and improves the performance of applications in low-quality network environments.

[0113] The data encryption and signature mechanism at the protocol layer protects the security of data during transmission and increases the privacy of user data. In addition, dynamic configuration and protocol design enable the system to quickly adapt to business changes and simplify the update and maintenance process.

[0114] In this embodiment, regarding step S2, loading: based on the data packet formed in step S1, a loading request is sent to the js resource to form return data, which includes the following steps S200-S201.

[0115] Specifically, step S200, resource mounting: after the loading request is confirmed, the jsBridge resource is mounted; the method flow is as follows:

[0116] Loading request confirmation (S2000): The application first confirms whether the data packet constructed in step S1 has been successfully delivered to the server and obtains the server's preliminary response confirmation. This process is implemented through HTTP status code or custom response header. If the confirmation is successful, the system will proceed to the next step; if it fails, an error report will be sent to the server immediately to facilitate rapid problem location.

[0117] Initialize jsBridge (S2001): The client application initializes the jsBridge component, which is a bridge for communication between JavaScript and native platforms (such as Android or iOS). Through jsBridge, the H5 page can call native code functions to improve performance and user experience.

[0118] Mounting resources (S2002): After jsBridge is ready, the required JS resource files are mounted to the current running environment. This may involve dynamic script injection, that is, injecting remote or local JS code snippets into the H5 page through jsBridge to achieve specific functions or optimize logic.

[0119] It is understandable that in step S200, through jsBridge, the H5 page can take advantage of the efficient execution capability of native code, reduce JavaScript execution time, and significantly improve response speed, especially for computationally intensive tasks. The close integration of native functions and H5 content enables developers to take advantage of device hardware capabilities, such as accessing local files, calling system services, etc., without requiring users to install complete native applications.

[0120] Specifically, step S201, cache: based on the data packet sent in step S101 (including request parameters and coverage data) and the jsBridge resource mounting in step S200, a request return command is sent and the return data is cached.

[0121] Update the configuration data of the previous request at the time specified by the client and save it to disk. Read the hit logic based on the returned data and supplement the fault tolerance logic of the returned data.

[0122] The method flow is as follows:

[0123] Construct cache instructions (S2010): Construct a cache policy instruction based on the data package in the previous step and the mounted jsBridge, including cache validity period and cache version control information to ensure the timeliness and correctness of cache data.

[0124] Send a request and cache data (S2011): execute a loading request to obtain JS resources, and then store the data in a client cache system, such as a SQLite database or a file system, according to the constructed cache instructions.

[0125] Update configuration data (S2012): Update configuration information to disk at an appropriate time point to ensure that the latest data can be used even when there is no network connection.

[0126] Cache hit logic (S2013): Implement logic to check the match between the new request and the cache content. If there is a match and the data is valid, the cached data is used directly to avoid repeated network requests.

[0127] Fault-tolerant processing (S2014): When cached data is unavailable or expired, the system automatically triggers a retry mechanism and re-initiates a network request to ensure functional continuity and stability.

[0128] It is understandable that through caching, a large number of repeated JS resource requests can be avoided, significantly shortening the page loading time, especially in a slow network environment. Frequently accessed resources are read from the local cache, reducing the data consumption of mobile devices. The faster page loading speed reduces user waiting time and enhances the overall interaction fluency and satisfaction.

[0129] In this embodiment, regarding step S3, reading: based on the returned data of step S2, reading and parsing its cache, refreshing and loading H5 data, including the following steps S300-S302.

[0130] Specifically, step S300: before attempting to read data from the cache, first check whether the cache item exists, whether the data is complete, and whether it is still valid through a verification mechanism. This step usually involves reading the metadata of the cache item, such as the storage timestamp and expiration time.

[0131] Once the cache is confirmed to be valid, the H5 resource data is directly extracted from the local storage (such as IndexedDB, LocalStorage or file system), avoiding network requests and speeding up resource acquisition.

[0132] It is understandable that step S300 reduces the number of requests to the external server by using the cache, which greatly improves the page loading speed, especially when the network condition is poor. Loading content from the cache instantly allows users to experience faster response and increases the fluency of the application.

[0133] Specifically, step S301: parse the data in the cache using technologies such as JSON.parse to identify different types of resource content such as HTML, CSS, JS, etc. Create a sandbox environment for the JavaScript code to be executed to ensure the safe execution of the script without affecting the global state of the application.

[0134] Categorize the parsed resources to prepare for subsequent asynchronous loading, such as mapping CSS resources to style loading tasks and JS resources to script execution tasks.

[0135] It can be understood that, through parsing and classification in step S301, the system can load resources in a targeted manner, reduce unnecessary processing overhead, and improve loading efficiency. The sandbox environment isolates script execution and protects the main application from potential adverse effects of third-party scripts.

[0136] Specifically, step S302: before loading new content, properly clean or refresh the existing H5 content to ensure seamless transition between old and new content. Use asynchronous programming techniques such as async / await or Promise to load parsed resources on demand or in parallel to avoid blocking the UI thread.

[0137] When loading resources, implement error monitoring and handling mechanisms, such as displaying friendly prompts when resource loading fails, or trying to reload from an alternative source. After loading and rendering, activate the interactive logic on the page, including binding event listeners and processing AJAX requests, so that the H5 application functions are fully available.

[0138] It is understandable that the asynchronous loading mechanism of step S302 ensures that the page can still respond to user interaction when loading resources, thereby improving the user experience. Through the exception handling mechanism, the application's ability to recover in the event of resource loading exceptions is improved, reducing the risk of crashes.

[0139] Embodiment 2: Based on Embodiment 1, this embodiment further provides an optimization method for step S2002: loading the script file through the URL, registering a callback function to monitor the loading status, and mounting the required loaded JS resources into the current running environment. The implementation method includes:

[0140] S20020, Dynamically create script tags: Use DOM operations to dynamically create script tags in the current page or <script>标签。这样做允许在运行时灵活地添加JavaScript资源,而无需预先静态嵌入到HTML中。

[0141] S20021,指定URL加载脚本:为新创建的<script>标签设置src属性,指向需要加载的外部JS文件的URL。这样,浏览器会异步发起对该脚本的请求,同时不会阻塞页面其他资源的加载或执行。

[0142] S20022,注册回调函数监听加载状态:利用onload和onerror事件监听器注册回调函数。当脚本成功加载并执行完毕时,onload事件触发,此时可以执行后续逻辑,如初始化某些组件或调用相关函数。若加载过程中发生错误,则通过onerror捕获异常,进行错误处理或重试机制的触发。

[0143] S20023,资源挂载与环境集成:在onload回调中,执行资源挂载逻辑,将加载完成的JS文件所定义的函数、类或变量等注册到全局作用域或特定模块中,使其成为当前运行环境的一部分,可供其他脚本或页面元素调用。

[0144] 可以理解的是,本实施例通过异步加载脚本,浏览器可以并行加载和执行多个资源,避免了传统同步加载时的阻塞问题,显著提升了页面的初始加载速度,使用户能更快看到页面内容。

[0145] 而且只有在确切需要时才加载特定的JS文件,避免了不必要的数据传输,减少了用户等待时间和带宽消耗。因此本方案对于大型应用尤其重要,因为它们包含多个功能模块,每个模块可能依赖不同的脚本文件。通过onerror事件的监听,可以即时捕获加载失败的情况,并采取相应措施,如切换备用资源链接、记录日志或尝试重新加载,提高了应用的健壮性和用户体验。

[0146] 并且动态加载鼓励模块化开发,每个功能块的代码可以独立加载和执行,易于管理和维护,同时也方便进行代码分割和懒加载策略的实施,进一步优化加载速度和内存使用。

[0147] 实施例三:本实施例在实施例一的基础上,进一步提供一个对步骤S2011的优化方法:

[0148] 执行之前构建的加载请求,获取到实际的js资源数据后,根据缓存策略将其存储在客户端的缓存系统中。

[0149] 在本实施例中,缓存策略为:LRU策略和TTL策略的结合,其方法为:

[0150] S20110,LRU策略实施:在客户端缓存系统中,为每一份缓存的JS资源分配一个访问时间戳和一个引用计数器。每当资源被访问或请求时,更新其访问时间戳和增加引用计数。

[0151] 当缓存空间接近上限时,系统自动移除那些最近最少被访问且引用计数较低的资源,以腾出空间给新资源或更频繁访问的资源。这一策略确保了经常被使用的资源得以保留,减少了因频繁请求造成的网络延迟。

[0152] S20111,TTL策略实施:为每个缓存的资源设置一个生命周期(TTL),即一个固定的过期时间。当资源过期时,无论其访问频率如何,都会被自动从缓存中清除。防止了因长时间未更新而可能导致的资源陈旧问题。

[0153] 优选的,TTL值通过HTTP响应头中的Cache-Control或Expires字段获取服务器推荐的缓存时长。

[0154] S20112,联合实施:先检查请求的资源是否存在于缓存中,如果存在则进一步检查是否已过期(根据TTL)。未过期的资源,再依据LRU策略决定是否需要替换。这样,既确保了资源的新鲜度,又保持了缓存的高效利用。

[0155] 可以理解的是,通过LRU策略,频繁使用的资源得以保留在缓存中,减少了对服务器的重复请求,显著加快了页面加载速度,尤其是在用户频繁操作或重新访问相同页面时。TTL策略确保了缓存数据不会过时,即使用户长时间停留在同一页面或应用中,也能获得最新内容,避免了因使用过期数据导致的用户体验问题。

[0156] 可以理解的是,结合LRU和TTL策略,有效地平衡了缓存资源的存储需求与可用性,避免了无限制的缓存增长,减轻了客户端设备的存储压力,尤其是对于内存资源有限的移动设备。快速的资源获取减少了页面渲染的等待时间,提升了整体应用的响应速度和流畅度,增强了用户体验。

[0157] 实施例四:本实施例在实施例三的基础上,进一步提供一个对步骤S2012的缓存管理策略的优化方案:

[0158] 在步骤S2011中,基于LRU策略和TTL策略的结合,先检查请求的资源是否存在于缓存中,如果存在则进一步检查是否已过期(根据TTL)。未过期的资源,再依据LRU策略决定是否需要替换。

[0159] 进而在步骤S2012中,基于步骤S011的结合结果,按照选择策略选择客户端确定的合适时机是应用启动、页面加载完成还是定期维护时。方法为:

[0160] S20120,初始化缓存管理系统,:首先,根据应用特性设定缓存的最大容量、TTL阈值以及LRU淘汰策略的参数。集成LRU与TTL算法的缓存库或自定义实现,确保系统能够自动管理缓存条目。

[0161] S20121,实时监测与评估:为每个缓存条目维护访问记录,包括访问时间戳和访问频次。定期或在每次资源请求时,检查缓存条目的TTL,判断是否过期。

[0162] S20122,LRU评估与资源替换:当缓存接近满载或需要替换资源时,根据LRU算法对所有缓存条目按照最后访问时间排序。

[0163] 从排序列表的末尾开始检查,淘汰最久未访问且非锁定(正在使用中)的条目,直至满足新的缓存需求或达到预设的容量限制。

[0164] S20123,更新时机智能选择:按照如下规则,选择相应的时机:

[0165] (1)应用启动时:

[0166] 检查关键业务数据的缓存情况,优先更新或预加载。

[0167] 利用用户等待启动画面的时间,进行后台缓存更新。

[0168] (2)页面加载完成:

[0169] 分析本次页面加载过程中涉及的资源,对比缓存情况,对频繁或即将访问的资源进行预加载或更新。

[0170] 利用页面渲染完成到用户交互的空档期进行优化。

[0171] (3)定期维护:

[0172] 设定定时任务,如每天凌晨或用户使用低谷期,执行全量或增量的缓存数据检查与更新。根据服务器端资源更新通知,触发特定资源的缓存更新。

[0173] 可以理解的是,在本实施例的技术方案中,基于LRU(Least Recently Used,最近最少使用)和TTL(Time To Live,生存时间)策略的结合,旨在创建一个既能高效利用有限缓存资源,又能确保数据时效性的智能缓存系统。这种结合策略特别适合H5应用,因为它能显著提高页面加载速度,并优化资源的使用效率;

[0174] 缓存机制减少了对服务器的请求次数,尤其是对于重复访问的静态资源,如图片、CSS、JavaScript文件等,这些资源直接从本地缓存加载,极大地缩短了页面加载时间。由于LRU策略保证了常用资源的即时可用性,用户在操作过程中能感受到更流畅的体验,减少等待时间。

[0175] TTL限制了无用数据在缓存中的停留时间,避免了缓存膨胀,确保了宝贵的缓存空间被有效循环利用。结合策略能够根据实时访问模式动态调整缓存内容,比如在高峰时段优先保留热门资源,低峰时段清理较少访问的内容,从而灵活适应不同的流量需求。

[0176] 而根据应用启动、页面加载完成或定期维护的不同时机选择性更新缓存,使得缓存管理策略更加灵活,能够更好地适应不同应用的特性和用户行为模式。且这个方法不涉及任何机器学习或回归任务模式,就可实现自适应性调整。

[0177] 以上所有实施例仅表达了本发明的相关实际应用的实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干变形和改进,这些都属于本发明的保护范围。因此,本发明专利的保护范围应以所附权利要求为准。

[0178] 对于本领域技术人员而言,还可以进一步意识到结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。

[0179] 同时本领域技术人员可以理解实现上述所有实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的和实施例中所使用的对存储器、存储、数据库或其他介质的任何引用,均可包括非易失性和 / 或易失性存储器。非易失性存储器可以包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(SSRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM),以及存储器总线动态RAM(RDRAM)等。< / script>

Claims

1. A method for accelerating H5 loading, characterized in that: The steps include: S1, download H5 static resources, select the specified configuration, form request parameters and coverage data, and send a business request; S2, based on the data packet formed in S1, sends a loading request to the js resource to form return data; S3, reads the returned data and parses its cache, refreshes and loads out H5 data.

2. The method for accelerating H5 loading according to claim 1, characterized in that: In S1, the method of selecting and sending is: while downloading, reading the configuration protocol of the preceding request and the cache reading protocol of the preceding request to form a data packet.

3. The method for accelerating H5 loading according to claim 2, characterized in that: The formation of the data packet includes: Configuration protocol: extract the URL, HTTP method and standardized request header information corresponding to the business request from the configuration file, classify and extract the request parameters; Cache read protocol: Expand the configured request parameters to cover all H5 pages and form coverage data.

4. The method for accelerating H5 loading according to claim 3 is characterized in that: The request parameters include public parameters, business parameters and device information parameters; The coverage data includes extended configuration parameters, coverage data and cache logic integration.

5. The method for accelerating H5 loading according to claim 1, characterized in that: In the S2, the following cache scheme is also included: based on the data packet and the jsBridge resource mounting, a request return command is sent and the return data is cached; Update the configuration data of the previous request at the time specified by the client and save it to disk, read the hit logic based on the returned data, and supplement the fault-tolerant logic of the returned data.

6. The method for accelerating H5 loading according to claim 5, characterized in that: The implementation method of the cache solution is: Forming cache storage instructions for instructing the system on how to cache response data to be received; Execute the previously constructed loading request, obtain the actual js resource data, and store it in the client's cache system according to the cache strategy; At an appropriate time determined by the client, the configuration information of the previous request is updated with the newly received or updated data so that the updated data can be serialized and persistently stored on disk. Check the consistency of request parameters with existing cache entries and verify the validity of cached data to determine whether subsequent requests can obtain data directly from the cache.

7. The method for accelerating H5 loading according to claim 6, characterized in that: The cache strategy is an LRU strategy or a TTL strategy.

8. The method for accelerating H5 loading according to claim 6, characterized in that: The appropriate time includes when the application is started, when the page is loaded, or when regular maintenance is performed.

9. The method for accelerating H5 loading according to claim 6, characterized in that: When cached data is not available, the logic should automatically fall back to re-initiating a network request.

10. A system for accelerating H5 loading, characterized by: The system includes a processor and a memory connected to the processor, wherein program instructions are stored in the memory, and when the program instructions are executed by the processor, the processor executes the method for accelerating H5 loading as described in any one of claims 1-9.

Citation Information

Cited By

  • Rapid tax declaration method, system and device and storage medium

    CN119417631A

  • High-resolution image thumbnail caching and loading method and system of iOS terminal, terminal equipment and medium

    CN121188301A

  • An iOS terminal high-resolution image thumbnail caching and loading method, system, terminal device and medium

    CN121188301B

  • Data reading method and data writing method

    CN121326257A