Webpage resource loading method and device of application program, equipment and storage medium
By intercepting static resource loading requests from the web page interface and using hash values to retrieve the database cache, the problem of slow web page loading speed caused by instability in the network environment is solved, and more efficient content loading and improved user experience is achieved.
Patent Information
- Application Number
- CN202410894289.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-11-22
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When the network environment is unstable, the content of the web interface is loading slowly, which affects the user experience.
By intercepting static resource loading requests for web page interfaces in the application, use the preset hash algorithm to calculate the hash value of the web page resource address, and retrieve whether there is a matching cache record in the database. If it exists, load the local cache resource to avoid duplication download.
Improves the content loading efficiency of web interfaces and improves user experience, especially in the unstable network environment.
Smart Images

Figure CN119003903A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for loading web page resources of an application. Background Art
[0002] With the development of computer communication and Internet technology, the application of electronic devices is becoming more and more common. For example, smart mobile phones, personal digital assistants, handheld computers and desktop computers are becoming more and more widely used. There are also more and more various applications installed in electronic devices, providing users with rich information services. When browsing a target web page in an application, it is necessary to download the corresponding web page resources from the cloud server and load the web page resources into the web page interface in the application to display the web page content of the target web page.
[0003] However, each time you use an application to browse the web, you need to first download the web resources corresponding to the web interface before you can display the web content. The network environment is complex and changeable, especially in an unstable network environment, which can easily cause the web interface content to load slowly, affecting the user experience. Summary of the invention
[0004] The embodiments of the present application provide a method, apparatus, device and storage medium for loading web page resources of an application program, which solves the problem that the content loading speed of a web page interface is slow due to a complex and changeable network environment, thus affecting the user experience, and improves the content loading efficiency of the web page interface, effectively improving the user experience when the network environment is unstable.
[0005] In a first aspect, an embodiment of the present application provides a method for loading web page resources of an application, the method comprising:
[0006] Intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource;
[0007] Performing a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value;
[0008] Searching in a set database whether there is a first cache record matching the hash value, the first cache record including a first resource cache address;
[0009] In the case that the first cache record exists in the database, the local cache resource corresponding to the first resource cache address is read, and the local cache resource is loaded into the web page interface for displaying the static content of the web page interface.
[0010] In a second aspect, an embodiment of the present application further provides a webpage resource loading device for an application, comprising:
[0011] A request acquisition module, configured to intercept a static resource loading request of a web page interface in an application program, wherein the static resource loading request includes a web page resource address of a target static web page resource;
[0012] An address hash calculation module, configured to perform a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value;
[0013] A cache record retrieval module, configured to search a set database for a first cache record matching the hash value, wherein the first cache record includes a first resource cache address;
[0014] The resource loading module is configured to read the local cache resource corresponding to the first resource cache address when the first cache record exists in the database, and load the local cache resource to the web page interface for displaying the static content of the web page interface.
[0015] In a third aspect, an embodiment of the present application further provides a webpage resource loading device for an application program, the device comprising:
[0016] one or more processors;
[0017] a storage device configured to store one or more programs,
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the web resource loading method of the application described in the embodiment of the present application.
[0019] In a fourth aspect, an embodiment of the present application further provides a non-volatile storage medium storing computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are configured to execute the web page resource loading method of the application program described in the embodiment of the present application.
[0020] In the embodiment of the present application, by intercepting the static resource loading request of the web page interface in the application, the static resource loading request includes the web page resource address of the target static web page resource; hashing the web page resource address based on a preset hash algorithm to obtain a hash value; searching in the set database whether there is a first cache record matching the hash value, the first cache record includes the first resource cache address; if the first cache record exists in the database, read the local cache resource corresponding to the first resource cache address, and load the local cache resource to the web page interface for displaying the static content of the web page interface. It is realized that the association information storage of the local cache resource and the web page resource address is realized by setting up a database, and a database search based on hash values is introduced to improve the data query efficiency, which is conducive to quickly determining whether the target static web page resource already exists in the cache; by intercepting the static resource loading request of the web page interface in the application, the local cache resource corresponding to the static resource loading request in the cache is preferentially loaded, without the need to re-download the resource, thereby improving the content loading efficiency of the web page interface, and effectively improving the user experience in the case of an unstable network environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A flowchart of a webpage resource loading method for an application provided in an embodiment of the present application;
[0022] Figure 2 A flowchart of a web page resource loading method including a process of caching target static web page resources provided in an embodiment of the present application;
[0023] Figure 3 A flowchart of a web page resource loading method including a process of regularly updating static web page resources in a cache provided in an embodiment of the present application;
[0024] Figure 4 A flowchart of a web page resource loading method including a process of clearing cache records and local cache resources provided in an embodiment of the present application;
[0025] Figure 5 A flowchart of another web page resource loading method including a process of clearing cache records and local cache resources provided in an embodiment of the present application;
[0026] Figure 6 A flowchart of another web page resource loading method including a process of updating static web page resources in a cache provided in an embodiment of the present application;
[0027] Figure 7 A flowchart of another web page resource loading method including a process of clearing cache records and local cache resources provided in an embodiment of the present application;
[0028] Figure 8A structural block diagram of a webpage resource loading device provided in an embodiment of the present application;
[0029] Fig. 9 A schematic diagram of the structure of a web page resource loading device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the embodiments of the present application, rather than to limit the embodiments of the present application. It should also be noted that, for ease of description, only parts related to the embodiments of the present application are shown in the accompanying drawings, rather than all structures.
[0031] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0032] The web resource loading method of the application provided in the embodiment of the present application is used to display web pages in the web interface of the application, for example, social media apps, reading apps, and live broadcast apps, etc. The aforementioned applications can allow users to directly view web links or access related web content within the application by having a built-in web view. The several application scenarios listed above are only exemplary and explanatory. In actual applications, the web resource loading method can also be used in web access in other scenarios, and the embodiment of the present application does not limit this. The present application aims to provide a web resource loading method, device, equipment, and storage medium for an application to solve the problem that the content loading speed of the web interface is slow due to the complex and changeable network environment, which affects the user experience.
[0033] In the web resource loading method of the application provided in the embodiment of the present application, the execution subject of each step can be a computer device, which refers to any electronic device with data calculation, processing and storage capabilities, such as mobile phones, PCs (Personal Computers), tablet computers and other terminal devices, and can also be servers and other devices, which are not limited in the embodiment of the present application.
[0034] Figure 1The flowchart of a web resource loading method of an application provided in an embodiment of the present application can be implemented with a web resource loading device as the execution subject. Figure 1 As shown, the webpage resource loading method of the application program specifically includes the following steps:
[0035] Step S101: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0036] Among them, in the related art, each time the target web page is browsed in the application, a resource loading request is directly sent to the cloud server. After receiving the resource loading request, the cloud server can respond to the resource loading request with the relevant web page resources. By loading the relevant web page resources into the web page interface in the application, the web page content of the target web page can be displayed. However, the resource loading request can include a static resource loading request and a dynamic resource loading request. The static web page resources corresponding to the static resource loading request do not depend on the content generated in real time by the server, for example, an HTML file for defining the basic layout and content of the web page, a CSS file for describing the appearance and format of the web page, a JavaScript file for providing the interactivity and dynamic functions of the web page, etc. Therefore, each time the same web page is browsed, the static web page resources may be repeatedly downloaded, affecting the web page loading efficiency. In step S101, the static resource loading request is intercepted to avoid directly downloading the target static web page resources, so as to enter the subsequent judgment process of whether the target static web page resources are cached. In addition, the static resource loading request includes a webpage resource address of a target static webpage resource. The webpage resource address may be a URL (Uniform Resource Locator) for locating and accessing the static webpage resource of the target webpage.
[0037] Step S102: performing a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0038] Among them, in this embodiment, for the historical web pages browsed by the user, the static web page resources corresponding to the historical web pages will be cached. In order to quickly determine whether there is corresponding cache data for the intercepted static resource loading request, a database can be set up, and the database can be used to record the resource cache addresses corresponding to the historically loaded static web page resources in the cache. In order to improve the retrieval efficiency, the hash value of the web page resource address corresponding to the static web page resource can be selected to be associated and stored with its resource cache address in the cache by utilizing the characteristics that the hash value is a fixed length and has uniqueness, so that the hash value of the web page resource address corresponding to the static web page resource can be quickly retrieved and determined by the hash value of each web page resource address. Step S102 performs a hash calculation on the web page resource address in the intercepted static resource loading request to obtain a hash value, which is used for the subsequent retrieval of the resource cache address in the database. The preset hash algorithm can be an MD5 algorithm, a SHA algorithm, a RIPEMD-160 algorithm, etc., which is not limited in this application.
[0039] Step S103: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0040] In the database, each hash value is associated with a corresponding cache record. By searching the database to see whether there is an identical hash value, it can be determined whether there is a cache record that has cached the target static web page resource.
[0041] Step S104: when there is a first cache record in the database, read the local cache resource corresponding to the first resource cache address, and load the local cache resource into the web page interface for displaying the static content of the web page interface.
[0042] Among them, if the first cache record exists in the database, it means that the target static web page resource is currently cached. Through the first resource cache address in the first cache record, the corresponding local cache resource can be located, so that the local cache resource can be loaded into the web page interface first without re-downloading the target static web page resource. In addition, after the static content display of the web page interface is completed, the dynamic resource loading request can continue to be sent to obtain the dynamic web page resource of the target web page updated in real time, and the dynamic content can be displayed in the web page interface.
[0043] In the above, by intercepting the static resource loading request of the web page interface in the application, the static resource loading request includes the web page resource address of the target static web page resource; hashing the web page resource address based on a preset hash algorithm to obtain a hash value; searching in the set database whether there is a first cache record matching the hash value, the first cache record includes the first resource cache address; if the first cache record exists in the database, read the local cache resource corresponding to the first resource cache address, and load the local cache resource to the web page interface for displaying the static content of the web page interface. In the above scheme, by setting up a database to store the association information between the local cache resource and the web page resource address, and introducing a database search based on a hash value, the data query efficiency is improved, which is conducive to quickly determining whether the target static web page resource already exists in the cache; by intercepting the static resource loading request of the web page interface in the application, the local cache resource corresponding to the static resource loading request in the cache is loaded first, without the need to re-download the resource, thereby improving the content loading efficiency of the web page interface, and effectively improving the user experience in the case of an unstable network environment.
[0044] Figure 2 A flowchart of a webpage resource loading method including a process of caching target static webpage resources is provided in an embodiment of the present application. Figure 2 As shown, the webpage resource loading method specifically includes the following steps:
[0045] Step S201: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0046] Step S202: performing a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0047] Step S203: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0048] Step S204: when there is a first cache record in the database, read the local cache resource corresponding to the first resource cache address, and load the local cache resource into the web page interface for displaying the static content of the web page interface.
[0049] Step S205: If there is no first cache record in the database, download the target static web page resource based on the web page resource address, and load the target static web page resource into the web page interface to display the static content of the web page interface.
[0050] Among them, if the first cache record does not exist in the database, it means that the static resource loading request is the first access to the target web page, and the target static web page resource has not been cached. The target static web page resource pointed to by the web page resource address can be downloaded from the cloud server and loaded into the web page interface to display the static content.
[0051] Step S206: store the target static web page resource in the local cache, and add a second cache record in the database, wherein the second cache record includes a second resource cache address corresponding to the target static web page resource.
[0052] Among them, after step S205 completes the loading of the target static web page resource, the target static web page resource can be synchronously stored in the local cache, and a corresponding second cache record can be added to the database to store the second resource cache address corresponding to the target static web page resource, so that the cached target static web page resource can be quickly called when the target web page is loaded again later.
[0053] As mentioned above, downloading and caching the target static web page resources that do not have cache records can provide cache data support for revisiting the same target web page, which is conducive to improving the efficiency of reloading the target web page, effectively coping with possible adverse fluctuations in the network environment, and ensuring the user's web browsing experience.
[0054] Figure 3 A flowchart of a webpage resource loading method including a process of regularly updating static webpage resources in a cache is provided for an embodiment of the present application. The second cache record also includes a webpage resource address, such as Figure 3 As shown, the webpage resource loading method specifically includes the following steps:
[0055] Step S301: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0056] Step S302: performing a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0057] Step S303: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0058] Step S304: when there is a first cache record in the database, read the local cache resource corresponding to the first resource cache address, and load the local cache resource into the web page interface for displaying the static content of the web page interface.
[0059] Step S305: If there is no first cache record in the database, download the target static web page resource based on the web page resource address, and load the target static web page resource into the web page interface to display the static content of the web page interface.
[0060] Step S306: store the target static web page resource in the local cache, and add a second cache record in the database, wherein the second cache record includes a second resource cache address corresponding to the target static web page resource.
[0061] Step S307: Set the update check cycle.
[0062] Among them, since web developers may optimize and update the static web resources of the web page in order to improve the loading speed and performance of the web page, the local cache resources in the cache may have the problem of outdated versions. When accessing the web page again, it may still be necessary to download the updated static web resources, which is also prone to the problem of slow web page loading. Therefore, an update check cycle can be set for the cached static web resources to regularly perform update checks on the static web resources. The update check cycle can be used to periodically check whether the static web resource corresponding to the web resource address has been updated. The cycle time interval can be set by the developer based on the statistical average update frequency of the web page, which is not limited in this application.
[0063] Step S308: When the current system time reaches the time node of the update check cycle and it is detected that the application is not running, the web page resource address is read from the database and a query request is sent to the server, so that the server can feedback the resource update information when it is determined that the static web page resource corresponding to the web page resource address has been updated.
[0064] Among them, if the current system time reaches the time node of the update check cycle, it means that an update check of the local cached resources is required. If it is detected that the application is not running, it means that the user has not enabled the application. The resources can be updated in advance before entering the application to ensure the browsing experience of the user when enabling the application next time. In addition, after reading the web resource address, a query request can be sent to the server. If the server replies with resource update information, it means that the static web resource corresponding to the web resource address has been updated. For example, the server may return different status codes in response to the query request. Accordingly, the resource update information may be a 200OK status code, indicating that the resource has been updated, while other status codes, such as a 304Not Modified status code, indicate that the resource has not been updated.
[0065] Step S309: when the resource update information is received, download the first webpage update resource based on the webpage resource address, and replace the target static webpage resource in the local cache with the first webpage update resource.
[0066] If resource update information is received, the first web page update resource pointed to by the web page resource address can be downloaded and the target static web page resource in the local cache can be replaced to achieve the purpose of updating the static web page resource in the cache.
[0067] As described above, by setting an update check cycle for the static web page resources in the corresponding cache, the purpose of regularly checking whether the static web page resources in the cache have been updated can be achieved. The cached static web page resources can be updated in time when the application is not running, and the optimization changes of static web page resources in the web page can be effectively responded to, thereby ensuring the loading efficiency when users visit the web page with resource optimization.
[0068] Figure 4 A flowchart of a webpage resource loading method including a process of clearing cache records and local cache resources provided in an embodiment of the present application. The first cache record also includes a resource call time, and the resource call time is used to record the most recent use time of the local cache resource, such as Figure 4 As shown, the webpage resource loading method specifically includes the following steps:
[0069] Step S401: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0070] Step S402: performing a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0071] Step S403: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0072] Step S404: if the first cache record exists in the database, read the local cache resource corresponding to the first resource cache address, load the local cache resource into the web page interface to display the static content of the web page interface, and update the resource call time.
[0073] Among them, since the user may not visit the webpage again after the first visit, the local cache resources of the webpage stored in the local cache will become cold data, resulting in unnecessary waste of cache space. Therefore, the resource call time of the local cache resources can be stored in the database to record the most recent use time of the local cache resources, so as to facilitate the subsequent judgment of whether the local cache resources have not been called for a long time.
[0074] Step S405: When it is detected that the application is not running, the resource calling time is read from the database, and the resource calling time is subtracted from the current system time to obtain the time difference.
[0075] When it is detected that the application is not running, the local cache resources can be cleaned up. In step S405, the time difference can be obtained by subtracting the resource call time from the current system time, and the time difference can be used to reflect how long the local cache resource has not been called.
[0076] Step S406: When the time difference is greater than a preset time length, clear the first cache record and the local cache resource corresponding to the first resource cache address.
[0077] The preset time length may be used to limit the maximum allowed time interval between the last call of the local cache resource. The developer may set the preset time length based on the size of the cache space and the statistical data of the interval between users' repeated visits to the same web page. This application does not limit this. If the time difference is greater than the preset time length, it can be considered that the user is likely to no longer need to call the local cache resource, and the first cache record and the local cache resource corresponding to the first resource cache address may be cleared accordingly.
[0078] As mentioned above, by recording the resource call time of the local cache resources, an effective reference can be provided for determining the call time interval of the local cache resources. By comparing the calculated time difference with the preset time length, the local cache resources that have not been called for a long time can be reasonably determined, and the local cache resources can be cleared in time to release cache space, optimize the use of storage resources, and reduce cache pressure.
[0079] Figure 5 A flowchart of another webpage resource loading method including a process of clearing cache records and local cache resources provided by an embodiment of the present application. Among them, the first cache record also includes the resource storage time and the cumulative number of calls. The resource storage time is used to record the time when the local cache resource is stored in the local cache, and the cumulative number of calls is used to record the total number of historical times of loading the local cache resource, such as Figure 5 As shown, the webpage resource loading method specifically includes the following steps:
[0080] Step S501: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0081] Step S502: Perform a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0082] Step S503: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0083] Step S504: when there is a first cache record in the database, read the local cache resource corresponding to the first resource cache address, load the local cache resource into the web page interface to display the static content of the web page interface, and update the accumulated call count.
[0084] Among them, the user may rarely visit the webpage after the first visit, or the user may basically no longer visit the same webpage after visiting the same webpage many times, so the utilization rate of the local cache resources corresponding to the webpage stored in the local cache will be low, and at the same time, it will cause greater storage pressure on the cache space. Therefore, the cumulative number of calls to the local cache resources can be stored in the database to record the total number of historical times of loading the local cache resources, so as to facilitate the subsequent judgment of whether the call frequency of the local cache resources is low.
[0085] Step S505: When it is detected that the application is not running, read the resource storage time and the cumulative number of calls from the database, subtract the resource storage time from the current system time to obtain the resource storage duration, and divide the cumulative number of calls by the resource storage duration to obtain the average number of calls.
[0086] When it is detected that the application is not running, the local cache resources can be cleaned up. In step S505, the resource storage time can be subtracted from the current system time to obtain the resource storage time, and the average number of calls can be obtained by dividing the cumulative number of calls by the resource storage time. The average number of calls can be used to reflect the frequency of calls to the local cache resources.
[0087] Step S506: When the average number of calls is less than the first preset number of times, clear the first cache record and the local cache resource corresponding to the first resource cache address.
[0088] The first preset number of times may be used to limit the minimum allowed call frequency of the local cache resource. The developer may set the first preset number of times according to the size of the cache space and the statistical data of the frequency of users accessing web pages, and this application does not limit this. If the average number of calls is less than the first preset number of times, it can be considered that the user may rarely call the local cache resource, and the first cache record and the local cache resource corresponding to the first resource cache address may be cleared accordingly.
[0089] As mentioned above, by recording the cumulative number of calls to local cache resources, an effective reference can be provided for determining the frequency of calls to local cache resources. By comparing the calculated average number of calls with the first preset number of calls, it is possible to reasonably determine the local cache resources that are rarely called, and reasonably clear these local cache resources to release cache space and reduce unnecessary occupancy of cache space.
[0090] Figure 6 A flowchart of another webpage resource loading method including a process of updating a static webpage resource in a cache is provided for an embodiment of the present application. The first cache record also includes a webpage resource address, such as Figure 6 As shown, the webpage resource loading method specifically includes the following steps:
[0091] Step S601: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0092] Step S602: Perform a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0093] Step S603: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0094] Step S604: if there is a first cache record in the database, read the local cache resource corresponding to the first resource cache address, load the local cache resource into the web page interface to display the static content of the web page interface, and update the accumulated call count.
[0095] Step S605: When it is detected that the application is not running, read the resource storage time and the cumulative number of calls from the database, subtract the resource storage time from the current system time to obtain the resource storage duration, and divide the cumulative number of calls by the resource storage duration to obtain the average number of calls.
[0096] Step S606: When the average number of calls is less than the first preset number of times, clear the first cache record and the local cache resource corresponding to the first resource cache address.
[0097] Step S607: when the average number of calls is greater than the second preset number, read the webpage resource address from the database, and send a query request to the server, so that the server can feedback resource update information when it is determined that the static webpage resource corresponding to the webpage resource address is updated.
[0098] The second preset number of times can be a reference threshold for determining whether a user frequently visits the same web page. The developer can set the second preset number of times based on the statistical data of the frequency of users visiting the web page, which is not limited in this application. If the average number of calls is greater than the second preset number of times, it can be considered that the user needs to frequently call the local cache resource, and the local cache resource can be updated and checked, which is conducive to the latest version of the static web page resource.
[0099] Step S608: When the resource update information is received, a second webpage update resource is downloaded based on the webpage resource address, and the local cache resource is replaced with the second webpage update resource.
[0100] By comparing the calculated average number of calls with the second preset number of calls, the frequently called local cache resources can be reasonably determined, and when the local cache resources are updated, they are promptly replaced with the latest static web page resources, so as to avoid the need for re-downloading when the user calls the local cache resources again due to resource updates, which affects the web page loading efficiency and reduces the user's experience.
[0101] Figure 7 A flowchart of another webpage resource loading method including a process of clearing cache records and local cache resources provided by an embodiment of the present application. Among them, the first cache record also includes the cumulative browsing time, which is used to record the total historical browsing time of the user browsing the webpage interface, such as Figure 7 As shown, the webpage resource loading method specifically includes the following steps:
[0102] Step S701: intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource.
[0103] Step S702: Perform a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value.
[0104] Step S703: Search in a set database whether there is a first cache record matching the hash value, wherein the first cache record includes a first resource cache address.
[0105] Step S704: if there is a first cache record in the database, read the local cache resource corresponding to the first resource cache address, load the local cache resource into the web page interface to display the static content of the web page interface, and update the accumulated call count.
[0106] Step S705: When it is determined that the web page interface is closed, the accumulated browsing time is updated.
[0107] The accumulated browsing time is used to record the total historical time that the user browses the web page interface, which can reflect the user's interest in or demand for the web page content.
[0108] Step S706: When it is detected that the application is not running, the resource storage time and the cumulative number of calls are read from the database, the resource storage time is subtracted from the current system time to obtain the resource storage time, the cumulative number of calls is divided by the resource storage time to obtain the average number of calls, the cumulative browsing time is read from the database, the cumulative browsing time is divided by the cumulative number of calls to obtain the average browsing time.
[0109] Among them, since users may visit web pages less frequently but visit for a long time each time, we can choose to retain the local cache resources corresponding to the web page to effectively meet the user's interest needs. Therefore, in addition to calculating the average number of calls to local cache resources, we can also add the average browsing time calculation to comprehensively determine whether the local cache resources should be cleared.
[0110] Step S707: When the average number of calls is less than the first preset number of calls and the average browsing time is less than the preset browsing time, clear the first cache record and the local cache resource corresponding to the first resource cache address.
[0111] The preset browsing time can be a critical threshold for judging whether the user is interested in or has a need for the target web page. The developer can set the preset browsing time based on the statistical data of the time the user visits the web page. If the average number of calls is less than the first preset number, and the average browsing time is less than the preset browsing time, it can be considered that the user may rarely call the local cache resource, and the time for each web page browsing is very short, and the first cache record and the local cache resource corresponding to the first resource cache address can be cleared accordingly.
[0112] As described above, by comparing the comprehensive average number of calls with the first preset number, and the average browsing time with the second preset number, it is possible to more accurately meet the needs of users, effectively determine the local cache resources that need to be cleared, avoid mistakenly clearing the local cache resources corresponding to the web pages that the user is interested in or needs, and reasonably release cache space.
[0113] Figure 8 This is a structural block diagram of a webpage resource loading device provided in an embodiment of the present application. The device is configured to execute the webpage resource loading method of the application provided in the above embodiment, and has the corresponding functional modules and beneficial effects of the execution method. Figure 8 As shown, the device specifically includes:
[0114] The request acquisition module 101 is configured to intercept a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource;
[0115] The address hash calculation module 102 is configured to perform a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value;
[0116] A cache record retrieval module 103 is configured to retrieve whether there is a first cache record matching the hash value in a set database, where the first cache record includes a first resource cache address;
[0117] The resource loading module 104 is configured to read the local cache resource corresponding to the first resource cache address when there is a first cache record in the database, and load the local cache resource to the web page interface for displaying the static content of the web page interface.
[0118] In the above, by intercepting the static resource loading request of the web page interface in the application, the static resource loading request includes the web page resource address of the target static web page resource; hashing the web page resource address based on a preset hash algorithm to obtain a hash value; searching in the set database whether there is a first cache record matching the hash value, the first cache record includes the first resource cache address; if the first cache record exists in the database, read the local cache resource corresponding to the first resource cache address, and load the local cache resource to the web page interface for displaying the static content of the web page interface. In the above scheme, by setting up a database to store the association information between the local cache resource and the web page resource address, and introducing a database search based on a hash value, the data query efficiency is improved, which is conducive to quickly determining whether the target static web page resource already exists in the cache; by intercepting the static resource loading request of the web page interface in the application, the local cache resource corresponding to the static resource loading request in the cache is loaded first, without the need to re-download the resource, thereby improving the content loading efficiency of the web page interface, and effectively improving the user experience in the case of an unstable network environment.
[0119] In a possible embodiment, a resource cache module is further included, configured as follows:
[0120] If the first cache record does not exist in the database, download the target static web page resource based on the web page resource address, and load the target static web page resource into the web page interface to display the static content of the web page interface;
[0121] The target static web page resource is stored in the local cache, and a second cache record is added to the database, where the second cache record includes a second resource cache address corresponding to the target static web page resource.
[0122] In a possible embodiment, the second cache record further includes a web page resource address;
[0123] Correspondingly, it also includes a first resource updating module configured as follows:
[0124] Set the update check cycle;
[0125] When the current system time reaches the time node of the update check cycle and the application is detected to be in a non-running state, the webpage resource address is read from the database and a query request is sent to the server, so that the server can feedback the resource update information when it is determined that the static webpage resource corresponding to the webpage resource address is updated;
[0126] When the resource update information is received, the first webpage update resource is downloaded based on the webpage resource address, and the target static webpage resource in the local cache is replaced with the first webpage update resource.
[0127] In a possible embodiment, the first cache record further includes a resource call time, and the resource call time is used to record the most recent use time of the local cache resource;
[0128] Correspondingly, it also includes a first resource clearing module configured as follows:
[0129] Update resource call time;
[0130] When it is detected that the application is not running, the resource call time is read from the database, and the resource call time is subtracted from the current system time to obtain the time difference;
[0131] When the time difference is greater than a preset time length, the first cache record and the local cache resource corresponding to the first resource cache address are cleared.
[0132] In a possible embodiment, the first cache record further includes resource storage time and cumulative call times, wherein the resource storage time is used to record the time when the local cache resource is stored in the local cache, and the cumulative call times are used to record the total number of historical times of loading the local cache resource;
[0133] Correspondingly, it also includes a second resource clearing module configured as follows:
[0134] Update the cumulative number of calls;
[0135] When it is detected that the application is not running, the resource storage time and the cumulative number of calls are read from the database, the resource storage time is subtracted from the current system time to obtain the resource storage time, and the cumulative number of calls is divided by the resource storage time to obtain the average number of calls;
[0136] When the average number of calls is less than the first preset number of times, the first cache record and the local cache resource corresponding to the first resource cache address are cleared.
[0137] In a possible embodiment, the first cache record further includes a web page resource address;
[0138] Correspondingly, it also includes a second resource updating module configured as follows:
[0139] When the average number of calls is greater than the second preset number of times, the webpage resource address is read from the database, and a query request is sent to the server, so that the server feeds back resource update information when it is determined that the static webpage resource corresponding to the webpage resource address is updated;
[0140] When the resource update information is received, the second webpage update resource is downloaded based on the webpage resource address, and the local cache resource is replaced with the second webpage update resource.
[0141] In a possible embodiment, the first cache record further includes a cumulative browsing time, where the cumulative browsing time is used to record the total historical time for which the user browses the web page interface;
[0142] Accordingly, a third resource clearing module is also included, configured as follows:
[0143] When the web page interface is closed, the accumulated browsing time is updated;
[0144] Read the cumulative browsing time from the database, and divide the cumulative browsing time and the cumulative number of calls to get the average browsing time;
[0145] The second resource clearing module is further configured to:
[0146] When the average number of calls is less than the first preset number of times and the average browsing time is less than the preset browsing time, the first cache record and the local cache resource corresponding to the first resource cache address are cleared.
[0147] Fig. 9 A schematic diagram of the structure of a webpage resource loading device provided in an embodiment of the present application, such as Fig. 9 As shown, the device includes a processor 201, a memory 202, an input device 203 and an output device 204; the number of processors 201 in the device can be one or more. Fig. 9 A processor 201 is taken as an example; the processor 201, memory 202, input device 203 and output device 204 in the device can be connected by a bus or other means. Fig. 9The example of connecting via a bus is taken. The memory 202, as a computer-readable storage medium, can be configured to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the web resource loading method of the application in the embodiment of the present application. The processor 201 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 202, that is, implements the web resource loading method of the above-mentioned application. The input device 203 can be configured to receive input digital or character information, and generate key signal input related to user settings and function control of the device. The output device 204 may include a display device such as a display screen.
[0148] The webpage resource loading device for an application provided above can be used to execute the webpage resource loading method for an application provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0149] An embodiment of the present application also provides a non-volatile storage medium containing computer executable instructions. When the computer executable instructions are executed by a computer processor, they are configured to execute a web page resource loading method for an application described in the above embodiment, which includes: intercepting a static resource loading request of a web page interface in the application, the static resource loading request includes a web page resource address of a target static web page resource; performing a hash calculation on the web page resource address based on a preset hash algorithm to obtain a hash value; searching in a set database whether there is a first cache record matching the hash value, the first cache record including a first resource cache address; if the first cache record exists in the database, reading a local cache resource corresponding to the first resource cache address, and loading the local cache resource to the web page interface for displaying the static content of the web page interface.
[0150] Storage medium - any of various types of memory devices or storage devices. The term "storage medium" is intended to include: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media, optical storage; registers or other similar types of memory elements, etc. Storage media may also include other types of memory or combinations thereof. In addition, the storage medium may be located in the first computer system in which the program is executed, or may be located in a different second computer system, which is connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (e.g., in different computer systems connected via a network). The storage medium may store program instructions (e.g., embodied as a computer program) that can be executed by one or more processors.
[0151] Of course, the storage medium containing computer executable instructions provided in an embodiment of the present application is not limited to the above-mentioned method for loading web resources for an application, and can also execute related operations in the method for loading web resources for an application provided in any embodiment of the present application.
[0152] It should be noted that the numbering of each step in this scheme is only used to describe the overall design framework of this scheme, and does not represent the necessary order relationship between the steps. On the basis that the overall implementation process conforms to the overall design framework of this scheme, it belongs to the protection scope of this scheme, and the order of precedence in the form of text during description is not an exclusive limitation on the specific implementation process of this scheme. It should be understood by those skilled in the art that the embodiments of the present application can be provided as methods, systems, or computer program products. In a typical configuration, a computing device includes one or more processors (CPU), an input / output interface, a network interface, and a memory. The memory may include non-permanent memory in a computer-readable medium, a random access memory (RAM) and / or a non-volatile memory in the form of a read-only memory (ROM) or a flash memory (flash RAM). The memory is an example of a computer-readable medium.
[0153] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0154] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A webpage resource loading method for an application, characterized in that: include: Intercepting a static resource loading request of a web page interface in an application, wherein the static resource loading request includes a web page resource address of a target static web page resource; Performing a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value; Searching in a set database whether there is a first cache record matching the hash value, the first cache record including a first resource cache address; In the case that the first cache record exists in the database, the local cache resource corresponding to the first resource cache address is read, and the local cache resource is loaded into the web page interface for displaying the static content of the web page interface.
2. The webpage resource loading method according to claim 1, characterized in that: Also includes: If the first cache record does not exist in the database, downloading the target static web page resource based on the web page resource address, and loading the target static web page resource into the web page interface for displaying the static content of the web page interface; The target static web page resource is stored in a local cache, and a second cache record is added to the database, wherein the second cache record includes a second resource cache address corresponding to the target static web page resource.
3. The webpage resource loading method according to claim 2, characterized in that: The second cache record also includes the web page resource address; After adding the second cache record in the database, the method further includes: Set the update check cycle; When the current system time reaches the time node of the update check cycle and it is detected that the application is not running, the webpage resource address is read from the database and a query request is sent to the server, so that the server feeds back resource update information when it is determined that the static webpage resource corresponding to the webpage resource address is updated; When the resource update information is received, a first webpage update resource is downloaded based on the webpage resource address, and the target static webpage resource in the local cache is replaced with the first webpage update resource.
4. The webpage resource loading method according to claim 1, characterized in that: The first cache record also includes a resource call time, where the resource call time is used to record the most recent use time of the local cache resource; Correspondingly, after the local cache resource is loaded into the web page interface, the method further includes: Updating the resource calling time; When it is detected that the application is not running, reading the resource calling time from the database, and subtracting the resource calling time from the current system time to obtain a time difference; When the time difference is greater than a preset time length, the first cache record and the local cache resource corresponding to the first resource cache address are cleared.
5. The webpage resource loading method according to claim 1, characterized in that: The first cache record also includes a resource storage time and a cumulative number of calls, wherein the resource storage time is used to record the time when the local cache resource is stored in the local cache, and the cumulative number of calls is used to record the total number of times the local cache resource is loaded in history; Correspondingly, after the local cache resource is loaded into the web page interface, the method further includes: Updating the cumulative number of calls; When it is detected that the application is not running, the resource storage time and the cumulative number of calls are read from the database, the resource storage time and the current system time are subtracted to obtain the resource storage time, and the cumulative number of calls is divided by the resource storage time to obtain the average number of calls; When the average number of calls is less than a first preset number of times, the first cache record and the local cache resource corresponding to the first resource cache address are cleared.
6. The webpage resource loading method according to claim 5, characterized in that: The first cache record also includes the web page resource address; The method further comprises: When the average number of calls is greater than a second preset number of times, the webpage resource address is read from the database, and a query request is sent to the server, so that the server feeds back resource update information when it is determined that the static webpage resource corresponding to the webpage resource address is updated; When the resource update information is received, a second webpage update resource is downloaded based on the webpage resource address, and the local cache resource is replaced with the second webpage update resource.
7. The webpage resource loading method according to claim 5, characterized in that: The first cache record also includes a cumulative browsing time, where the cumulative browsing time is used to record the total historical time for which the user browses the web page interface; Correspondingly, after the local cache resource is loaded into the web page interface, the method further includes: When it is determined to close the webpage interface, updating the accumulated browsing time; After reading the resource storage time and the accumulated call times from the database, the method further includes: Read the accumulated browsing time from the database, and divide the accumulated browsing time and the accumulated number of calls to obtain an average browsing time; When the average number of calls is less than a first preset number of times, clearing the first cache record and the local cache resource corresponding to the first resource cache address includes: When the average number of calls is less than a first preset number and the average browsing duration is less than a preset browsing duration, the first cache record and the local cache resource corresponding to the first resource cache address are cleared.
8. A webpage resource loading device, characterized in that: include: A request acquisition module, configured to intercept a static resource loading request of a web page interface in an application program, wherein the static resource loading request includes a web page resource address of a target static web page resource; An address hash calculation module, configured to perform a hash calculation on the webpage resource address based on a preset hash algorithm to obtain a hash value; A cache record retrieval module, configured to search a set database for a first cache record matching the hash value, wherein the first cache record includes a first resource cache address; The resource loading module is configured to read the local cache resource corresponding to the first resource cache address when the first cache record exists in the database, and load the local cache resource to the web page interface for displaying the static content of the web page interface.
9. A webpage resource loading device, the device comprising: one or more processors; A storage device is configured to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the web page resource loading method described in any one of claims 1 to 7.
10. A non-volatile storage medium storing computer executable instructions, wherein the computer executable instructions are configured to execute the webpage resource loading method according to any one of claims 1 to 7 when executed by a computer processor.
Citation Information
Patent Citations
Resource caching method and device, computer equipment and storage medium
CN110555184A
Static resource caching method, system and device, computer equipment and storage medium
CN110866198A
Static resource loading method and device, equipment and storage medium
CN113568752A
Page generation method and device, electronic equipment and computer readable storage medium
CN117493721A
Cited By
Page display method and device, equipment, medium and program product
CN119718522A
