Resource loading method and device, computer equipment and storage medium
By using the main thread in the middleware to load resources from multiple resource storage units and determine the retry scheme of asynchronous threads based on the cause of failure, the low success rate and page blocking problems when resource loading fails in traditional resource loading methods are solved, and the user experience is improved.
Patent Information
- Application Number
- CN202510211056.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-25
- Publication Date
- 2025-05-27
AI Technical Summary
Traditional resource loading methods require user to refresh manually when resource loading fails. Retrieval cannot be retryed in combination with the reasons for loading failure, resulting in a low retry success rate. In addition, the main thread is used to cause page blockage during resource retry, affecting the user experience.
When the middleware listens to the resource loading request for the target page, the resource is loaded from multiple resource storage units through the main thread. If all storage units fail to load, determine the target retry scheme based on the cause of failure, and use an asynchronous thread to retry the resource. After success, the resource is provided to the main thread for loading and display.
It improves the success rate of resource retry, avoids the need for user manual refresh, reduces page blockage, and improves user experience.
Smart Images

Figure CN120045802A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer resource loading, and particularly to a resource loading method, apparatus, computer device, and storage medium. Background Art
[0002] With the rapid development of the Internet, the performance of network resource loading directly affects the user experience. Especially in modern Web applications, the speed and stability of resource loading are crucial for user retention. However, in the context of changing network environments and complex resource requests, traditional resource loading methods require users to manually refresh for simple linear retries when resource loading fails, unable to combine the reasons for loading failures for resource retries, nor ensure the success rate of resource retries, and causing page blocking when performing resource retries using the main thread, which will lead to a decrease in user retention rate. Summary of the Invention
[0003] This application provides a resource loading method, apparatus, computer device, and storage medium to solve the problems that when resource loading fails under the existing traditional resource loading method, users need to manually refresh for simple linear retries, resulting in a low success rate of resource retries, and page blocking occurs when performing resource retries.
[0004] In a first aspect, this application provides a resource loading method, which includes:
[0005] When the middleware monitors a resource loading request corresponding to a target page, load the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread, where the resource loading request is used to request to load the target resource;
[0006] When the target resource fails to be loaded in each of the resource storage units, determine a target retry plan corresponding to the target resource according to the reason for the loading failure of the target resource;
[0007] Use an asynchronous thread to re-obtain the target resource according to the target retry plan;
[0008] When the target resource is successfully obtained according to the target retry plan, provide the target resource to the main thread for loading and display.
[0009] In a second aspect, this application provides a resource loading apparatus, which includes:
[0010] A loading module, configured to, when the middleware monitors a resource loading request corresponding to a target page, load the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread, where the resource loading request is used to request to load the target resource;
[0011] A determination module, configured to determine a target retry scheme corresponding to the target resource according to the reason for the loading failure of the target resource when the loading of the target resource fails for each of the resource storage units;
[0012] A retry module, configured to use an asynchronous thread to re-obtain the target resource according to the target retry scheme;
[0013] A display module, configured to provide the target resource to the main thread for loading and displaying when the target resource is successfully obtained according to the target retry scheme.
[0014] In a third aspect, the present application provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the above resource loading method is implemented.
[0015] In a fourth aspect, the present application further provides a computer storage medium, storing computer-executable instructions for executing the above resource loading method.
[0016] The above technical solution provided by the embodiments of the present application has the following advantages compared with the prior art: In the method provided by the embodiments of the present application, when the middleware monitors a resource loading request corresponding to a target page, the main thread is used to load the target resource corresponding to the resource loading request from multiple different resource storage units, where the resource loading request is used to request to load the target resource; when the loading of the target resource fails for each of the resource storage units, a target retry scheme corresponding to the target resource is determined according to the reason for the loading failure of the target resource; an asynchronous thread is used to re-obtain the target resource according to the target retry scheme; when the target resource is successfully obtained according to the target retry scheme, the target resource is provided to the main thread for loading and displaying.
[0017] Based on the above method, the middleware is used to monitor the resource loading request corresponding to the target page, the main thread is used to load the target resource required by the resource loading request from different channels simultaneously, the target resource is re-obtained in combination with the reason for the loading failure when the query of the target resource fails, and the target resource re-obtained by the resource is loaded and displayed through the main thread, so that the retry success rate of the target resource can be improved. The retry process is automatically executed without the need for the user to manually refresh, and the resource retry is performed through an asynchronous thread, thereby avoiding blocking the main thread during resource retry, so as to solve the problems that the resource retry success rate is relatively low when the resource loading fails in the existing traditional resource loading method and the page is blocked during resource retry. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings here are incorporated into the description and form a part of this description, showing embodiments consistent with the present invention, and are used together with the description to explain the principles of the present invention.
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0020] One or more embodiments are exemplarily illustrated by the pictures in the corresponding accompanying drawings. These exemplary illustrations do not limit the embodiments. Elements with the same reference numerals in the drawings represent similar elements, unless otherwise stated, and the drawings in the figures do not constitute a proportional limitation.
[0021] Figure 1 An application environment diagram of a resource loading method provided for an embodiment of this application;
[0022] Figure 2 A flowchart of a resource loading method provided for an embodiment of this application;
[0023] Figure 3 A flowchart of a resource loading method provided for an embodiment of this application;
[0024] Figure 4 A flowchart of a resource loading method provided for an embodiment of this application;
[0025] Figure 5 A structural block diagram of a resource loading device provided for an embodiment of this application;
[0026] Figure 6 An internal structural diagram of a computer device provided for an embodiment of this application. Detailed implementation manners
[0027] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are some but not all of the embodiments of this application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of this application without creative efforts belong to the scope of protection of this application.
[0028] The following disclosure provides many different embodiments or examples for implementing different structures of the present invention. To simplify the disclosure of the present invention, the components and settings of specific examples are described below. Of course, they are only examples and are not intended to limit the present invention. In addition, the present invention may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0029] Figure 1 It is an application environment diagram of a resource loading method in an embodiment. Refer to Figure 1 , this resource loading method is applied to a resource loading system. The resource loading system includes a terminal 110 and a server 120. The terminal 110 and the server 120 are connected through a network. The terminal 110 can specifically be a desktop terminal or a mobile terminal, and the mobile terminal can specifically be at least one of a mobile phone, a tablet computer, a laptop computer, etc. The server 120 can be implemented by an independent server or a server cluster composed of multiple servers.
[0030] In one embodiment, Figure 2 It is a schematic flowchart of a resource loading method in an embodiment. Refer to Figure 2 , a resource loading method is provided. In this embodiment, it is mainly illustrated by applying this method to the terminal 110 in the above Figure 1 . The resource loading method specifically includes the following steps:
[0031] Step S210, when the middleware listens to a resource loading request corresponding to a target page, load the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread, where the resource loading request is used to request to load the target resource.
[0032] Specifically, the middleware is the Service Worker, which is used to listen to and intercept resource loading requests of web pages. The business code does not need to directly control the resource loading logic, reducing the development complexity and improving the generality. The target page is a web page of any browser in the terminal 110 that has completed domain name registration in the middleware. The terminal 110 loads the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread at the same time. The target resource is the resource that the resource loading request is to request, and the target resource can specifically be web page materials, online tools, design tools, graphic resources, audio resources, video resources, etc. Request the target resource from multiple resource storage units at the same time to increase the loading success rate of the target resource.
[0033] Step S220, when the loading of the target resource fails in each of the resource storage units, determine the target retry plan corresponding to the target resource according to the reason for the failure of the target resource to be loaded.
[0034] Specifically, if the loading of the target resource fails from each resource storage unit, the resource retry scheme for the target resource is further determined in combination with the reason for the failure to load the target resource. Selecting the resource retry scheme on the basis of the acquisition failure can improve the success rate of reacquiring the target resource, and the target retry scheme is a resource retry strategy that can successfully acquire the target resource to the greatest extent possible.
[0035] Step S230, use an asynchronous thread to reacquire the target resource according to the target retry scheme.
[0036] Specifically, using an asynchronous thread to reacquire the target resource according to the target retry scheme, that is, using an exception thread for resource retry, avoids blocking the main thread by using the main thread for resource retry.
[0037] Step S240, when the target resource is successfully acquired according to the target retry scheme, provide the target resource to the main thread for loading and display.
[0038] Specifically, when the asynchronous thread acquires the target resource according to the target retry scheme, the target resource acquired by the asynchronous thread is sent to the main thread for loading and display. The above resource retry process uses middleware to monitor the resource loading request corresponding to the target page, and the main thread loads the target resource required by the resource loading request from different channels at the same time. When the query of the target resource fails, the target resource is reacquired in combination with the reason for the loading failure, and the target resource reacquired by the resource is loaded and displayed by the main thread, so that the retry success rate of the target resource can be improved. The retry process is automatically executed without the user manually refreshing, and resource retry is performed through an asynchronous thread, thus avoiding blocking the main thread during resource retry, so as to solve the problems that when the resource loading fails in the existing traditional resource loading method, the user needs to manually refresh for simple linear retry, resulting in a low resource retry success rate, and page blocking occurs during resource retry.
[0039] In one embodiment, referring to Figure 4 , when the middleware monitors the resource loading request corresponding to the target page, the main thread loads the target resource corresponding to the resource loading request from multiple different resource storage units, including:
[0040] When the middleware monitors the resource loading request corresponding to the target page, the main thread races to load the target resource corresponding to the resource loading request from multiple different resource storage units, where the multiple different resource storage units include the server 120 and multiple different preset caches;
[0041] After the main thread races to load the target resource corresponding to the resource loading request from multiple different resource storage units, the method further includes:
[0042] Provide the target resource first loaded from multiple different resource storage units to the main thread for loading and display.
[0043] Specifically, when the middleware monitors a resource loading request, it will race to load the target resource from multiple different resource storage units through the main thread. The multiple different resource storage units include Server 120 and multiple different preset caches. The multiple different preset caches include Http strong cache, negotiation cache, disk cache, memory cache, ServiceWorker cache, etc. The resource loading speed of the preset cache is greater than that of Server 120. Using multiple different resource storage units to race to load the target resource means loading the target resource through multiple resource loading channels simultaneously, and providing the target resource first provided by the multiple resource storage units to the main thread for loading and display. By loading the target resource simultaneously through multiple resource storage units, not only can the loading success rate of the target resource be improved, but also the display efficiency of the target resource can be improved through the race loading of multiple resource storage units, so as to shorten the display time of the target resource in the target page, thereby optimizing the user's browsing experience of the target page.
[0044] In one embodiment, referring to Figure 4 , after providing the target resource first loaded from multiple different resource storage units to the main thread for loading and display, the method further includes:
[0045] When the loading source of the target resource is the target cache, receive the response result of Server 120 for the resource loading request in the background, where the target cache is any one of the preset caches;
[0046] When the response result of Server 120 for the resource loading request is a successful response, use the target resource in the response result to replace the target resource in the target cache.
[0047] Specifically, when caching the target resource at the loading source of the target resource, it means that the target cache provides the target resource first through a race. At this time, it is also necessary to receive the response result of the resource loading request from the background receiving server 120. The target cache can be any preset cache, and the resources stored in the preset cache are historical resources that the terminal 110 previously requested from the server 120. If the response result feedback by the server 120 for the resource loading request is a successful response, it means that the server 120 provides the latest version of the target resource for the resource loading request. However, the target resource in the target cache may be an old version resource. Therefore, after using the target resource provided by the target cache to be preferentially displayed on the target page, the background replaces the target resource in the target cache with the latest version of the target resource provided by the server 120 to update the version of the target resource in the target cache, so that the target cache can quickly provide the latest version of the target resource for the terminal 110 when the terminal 110 requests the target resource next time.
[0048] In one embodiment, referring to Figure 4 , after receiving the response result of the server 120 for the resource loading request through the background, the method further includes:
[0049] When the response result of the server 120 for the resource loading request is a failed response, determine the network status of the target page;
[0050] When the network status is network available, delete the resources in the specified cache whose access times are lower than the preset access times, where the specified cache includes at least one of the preset caches.
[0051] Specifically, in the case where the terminal 110 uses the target resource provided by the target cache for display, when the response result of the server 120 for the resource loading request received through the background is a failed response, it is necessary to reproduce and determine whether the network status of the target page is in an online state. If the network status of the target page is network available, that is, it is determined that the network is online, then delete the resources in the specified cache whose access times are lower than the preset access times, and the specified cache can be at least one preset cache among Http strong cache, negotiation cache, disk cache, memory cache, and Service Worker cache, so as to update the resources that are not frequently used in the preset cache, thereby releasing part of the storage space of the preset cache, which is beneficial to storing the latest resources requested by the terminal 110 from the server 120 subsequently.
[0052] In one embodiment, according to the reason for the loading failure of the target resource, determine the target retry scheme corresponding to the target resource, including:
[0053] When the reason for the loading failure of the target resource is a network exception, the first retry scheme is determined as the target retry scheme, where the first retry scheme is used to send the resource loading request to the server when the target page is in the first network communication state. If the re-acquisition of the target resource fails when the target page is in the first network communication state, the re-acquisition of the target resource is paused and the network change event corresponding to the target page is monitored; when it is monitored that the target page changes from the first network communication state to the second network communication state, the resource loading request is sent to the server again, and the first network communication state and the second network communication state correspond to different communication methods; or,
[0054] When the reason for the loading failure of the target resource is a server exception, the second retry scheme is determined as the target retry scheme, where the second retry scheme is used to obtain the target resource from a preset cache.
[0055] Specifically, the reason for the loading failure of the target resource is determined by intercepting the running event (fetch event), and the reason for the loading failure is classified, so as to determine the resource retry scheme suitable for the reason for the loading failure. For network exceptions, that is, regarded as simple network errors, the first retry scheme is selected as the target retry scheme.
[0056] When the target retry scheme is the first retry scheme, using an asynchronous thread to re-acquire the target resource according to the target retry scheme includes: when the target page is in the first network communication state, using the asynchronous thread to send the resource loading request to the server; if the re-acquisition of the target resource is successful when the target page is in the first network communication state, sending the target resource to the main thread for loading and display. The network communication state is used to indicate the network communication method of the target page, specifically including the mobile network communication state and the local area network communication state. The mobile network communication state includes the mobile communication states supported by different operators, and the local area network communication method includes the network communication states corresponding to different local area networks. Therefore, the first network communication state can be any mobile communication state supported by an operator or the network communication state corresponding to any local area network; if the re-acquisition of the target resource fails when the target page is in the first network communication state, suspending the re-acquisition of the target resource and listening for the network change event (online event) corresponding to the target page. The network change event refers to the listening event for the target page to change the network communication method; when it is detected that the target page changes from the first network communication state to the second network communication state, re-sending the resource loading request to the server, that is, detecting the network change event corresponding to the target page. The first network communication state and the second network communication state correspond to different communication methods, that is, when the terminal carrying the target page is in the first network communication state, the target resource cannot be successfully re-acquired, but after the network of the terminal carrying the target page changes, the server can be re-accessed to re-acquire the target resource. That is, for NetworkError (pure network error), the retry mechanism is entered. If the retry mechanism still fails, listen for the online event and wait for the user's mobile phone network to change and reconnect before retrying, so as to reduce the impact of the network state on the retry of the target resource.
[0057] When the reason for the loading failure of the target resource is server exception, that is, regarded as a server error, then select the second retry scheme as the target retry scheme. When the target retry scheme is the second retry scheme, using an asynchronous thread to re-acquire the target resource according to the target retry scheme includes: using the asynchronous thread to obtain the target resource from the preset cache, that is, resource degradation, taking the cached resource to improve the success rate of re-acquiring the target resource. If the target resource is not in the cache either, it is determined that the re-acquisition of the target resource fails.
[0058] In one embodiment, referring to Figure 3 , after using an asynchronous thread to re-acquire the target resource according to the target retry scheme, the method further includes:
[0059] When the acquisition of the target resource using the asynchronous thread fails, determining the cumulative number of retries;
[0060] Determine a preset number of retry attempts according to the network status of the target page;
[0061] When the cumulative number of retry attempts is less than the preset number of retry attempts, re-determine the target retry scheme corresponding to the target resource according to the reason for the loading failure of the target resource, and use an asynchronous thread to re-obtain the target resource according to the target retry scheme.
[0062] Specifically, after resource retry is performed on the target resource by an asynchronous thread according to the target retry method, if the target resource is still not obtained successfully, the cumulative number of retry attempts corresponding to the target resource is incremented. The cumulative number of retry attempts is the number of times the resource is reloaded for the current resource loading request. Determine the preset number of retry attempts according to the network status of the target page. The preset number of retry attempts is used to limit the number of resource retries and avoid wasting resources due to invalid multiple resource retries. The target page corresponds to different preset numbers of retry attempts in different network statuses. The network status is divided into a low-speed network and a high-speed network. The low-speed network means that the network transmission speed of the terminal carrying the target page is less than or equal to the preset transmission speed, and the high-speed network means that the network transmission speed of the terminal carrying the target page is greater than the preset transmission speed. When the cumulative number of retry attempts is less than the preset number of retry attempts, the resource loading request can be automatically sent to the server 120 again to perform resource retry in a loop, thereby increasing the loading success rate of the target resource.
[0063] In one embodiment, determining the preset number of retry attempts according to the network status of the target page includes:
[0064] When the network status of the target page is a low-speed network, determine the first preset number as the preset number of retry attempts;
[0065] When the network status of the target page is a high-speed network, determine the second preset number as the preset number of retry attempts, where the first preset number is less than the second preset number.
[0066] Specifically, when the network status of the target page is a network disconnection, suspend resource retry for the target resource, and monitor the network change event corresponding to the target page. When the network change event is monitored, perform resource retry again. When the network status of the target page is a high-speed network, it means that the network transmission speed of the terminal carrying the target page is relatively fast, so the larger second preset number is selected as the preset number of retry attempts. When the network status of the target page is a low-speed network, it means that the network transmission speed of the terminal carrying the target page is relatively slow, so the smaller first preset number is selected as the preset number of retry attempts to reduce the preset number of retry attempts and avoid long-term low-speed occupation of the network.
[0067] In one embodiment, with reference to Figure 3, after determining the cumulative retry count when the asynchronous thread fails to obtain the target resource, the method further includes:
[0068] When the cumulative retry count reaches a preset retry count, display preset content on the target page, where the preset content is used to indicate that the loading of the target resource fails.
[0069] Specifically, if the cumulative retry count reaches the preset retry count, it means that the number of times of reloading the target resource has reached the upper limit, and the target resource fails to be loaded after multiple reloads from the server 120. Then, give up retrying the target resource and display preset content on the target page. The preset content can specifically be at least one of text content, picture content, audio content, video content, etc. The preset content is used to inform the user that the loading of the target resource fails.
[0070] In one embodiment, when the middleware monitors a resource loading request corresponding to a target page, loading the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread includes:
[0071] When the middleware monitors multiple resource loading requests corresponding to a target page, determine the response priority of each resource loading request according to the resource type corresponding to each resource loading request;
[0072] According to the response priority corresponding to each resource loading request, sequentially load the target resource corresponding to each resource loading request from multiple different resource storage units through the main thread.
[0073] Specifically, if the middleware monitors multiple resource loading requests corresponding to a target page but cannot respond to multiple resource loading requests simultaneously, it is necessary to sort the response order of multiple resource loading requests. Specifically, determine the response priority of each resource loading request according to the resource type corresponding to each resource loading request. The resource types at least include core function resources, decorative resources, etc., and different resource types correspond to different response priorities. For example, usually, the loading speed of decorative resources is greater than that of core function resources. In order to provide the display screen to the user as soon as possible and avoid user loss due to too long waiting time, some display content will be provided to the user as soon as possible. Then, set the response priority of decorative resources to be the highest, so as to preferentially respond to the resource loading requests corresponding to decorative resources, so as to quickly provide graphic and text resources to the user and retain the user, and can also optimize the utilization rate of network bandwidth.
[0074] Sort based on the response priority corresponding to each resource loading request, and sequentially load the target resource corresponding to each resource loading request from multiple different resource storage units through the main thread according to the sorting result, so as to adapt to the application scenario of multiple resource loading requests.
[0075] Based on the above method, retrying and racing do not block the page. The service worker is independent of the main thread, through which the scenario of blank screen caused by resource loading failure due to factors such as network and CDN node jitter can be solved, retaining users and improving the user browsing experience. For the scenario of blank screen caused by resource loading failure, there is no need for the user to refresh or other methods to solve it. Instead, perform seamless retry to improve the experience. In network requests, caching is not necessarily faster than requests. Race to respond to network resources as quickly as possible, improve the resource response speed, and thus improve the page opening speed. Update cached resources in the background (resources that are not frequently used are changed), ensuring rapid iteration of versions.
[0076] Figures 2 to 4 It is a schematic flowchart of a resource loading method in an embodiment. It should be understood that although Figures 2 to 4 the steps in the flowchart are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, Figures 2 to 4 at least a part of the steps in
[0077] In one embodiment, as Figure 5 shown, a resource loading device is provided, including:
[0078] A loading module 310, configured to, when the middleware monitors a resource loading request corresponding to a target page, load a target resource corresponding to the resource loading request from multiple different resource storage units through the main thread, where the resource loading request is used to request to load the target resource;
[0079] A determination module 320, configured to, when all the resource storage units fail to load the target resource, determine a target retry scheme corresponding to the target resource according to the reason for the loading failure of the target resource;
[0080] A retry module 330, configured to use an asynchronous thread to re-obtain the target resource according to the target retry scheme;
[0081] A display module 340, configured to, when the target resource is successfully obtained according to the target retry scheme, provide the target resource to the main thread for loading and display.
[0082] In one embodiment, the loading module 310 is further configured to:
[0083] When the middleware monitors a resource loading request corresponding to a target page, race to load the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread, where the multiple different resource storage units include the server 120 and multiple different preset caches;
[0084] After racing to load the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread, the method further includes:
[0085] Provide the target resource first loaded from multiple different resource storage units to the main thread for loading and display.
[0086] In one embodiment, after providing the target resource first loaded from multiple different resource storage units to the main thread for loading and display, the loading module 310 is further configured to:
[0087] When the loading source of the target resource is a target cache, receive the response result of the server 120 for the resource loading request through the background, where the target cache is any one of the preset caches;
[0088] When the response result of the server 120 for the resource loading request is a successful response, use the target resource in the response result to replace the target resource in the target cache.
[0089] In one embodiment, after receiving the response result of the server 120 for the resource loading request through the background, the loading module 310 is further configured to:
[0090] When the response result of the server 120 for the resource loading request is a failed response, determine the network status of the target page;
[0091] When the network status is network available, delete the resources in the specified cache whose access times are lower than the preset retry times, where the specified cache includes at least one of the preset caches.
[0092] In one embodiment, the determining module 320 is further configured to:
[0093] When the reason for the loading failure of the target resource is a network exception, determine the first retry scheme as the target retry scheme, where the first retry scheme is used to send a resource loading request to the server when the target page is in a first network communication state. If the re - acquisition of the target resource fails when the target page is in the first network communication state, pause the re - acquisition of the target resource and monitor the network change event corresponding to the target page; when it is monitored that the target page changes from the first network communication state to a second network communication state, send the resource loading request to the server again, and the first network communication state and the second network communication state correspond to different communication methods; or,
[0094] When the reason for the loading failure of the target resource is a server exception, determine the second retry scheme as the target retry scheme, where the second retry scheme is used to obtain the target resource from a preset cache.
[0095] In one embodiment, the retry module 330 is further configured to:
[0096] When the acquisition of the target resource fails using the asynchronous thread, determine the cumulative retry count;
[0097] Determine a preset retry count according to the network state of the target page;
[0098] When the cumulative retry count is less than the preset retry count, re - determine the target retry scheme corresponding to the target resource according to the reason for the loading failure of the target resource, and use the asynchronous thread to re - obtain the target resource according to the target retry scheme.
[0099] In one embodiment, the retry module 330 is further configured to:
[0100] When the network state of the target page is a low - speed network, determine the first preset count as the preset retry count;
[0101] When the network state of the target page is a high - speed network, determine the second preset count as the preset retry count, where the first preset count is less than the second preset count.
[0102] In one embodiment, the retry module 330 is further configured to:
[0103] When the cumulative retry count reaches the preset retry count, display preset content on the target page, where the preset content is used to indicate that the loading of the target resource fails.
[0104] In one embodiment, the loading module 310 is further configured to:
[0105] When the middleware monitors multiple resource loading requests corresponding to the target page, determine the response priorities of the respective resource loading requests according to the resource types corresponding to the respective resource loading requests;
[0106] According to the response priorities corresponding to the respective resource loading requests, sequentially load the target resources corresponding to the respective resource loading requests from multiple different resource storage units through the main thread.
[0107] As Figure 6 shown, an embodiment of the present application provides a computer device, including a processor 711, a communication interface 712, a memory 713, and a communication bus 714. Among them, the processor 711, the communication interface 712, and the memory 713 complete mutual communication through the communication bus 714;
[0108] The memory 713 is used to store computer programs;
[0109] The processor 711 is used to implement the resource loading method provided by any one of the foregoing method embodiments when executing the program stored on the memory 713.
[0110] Those skilled in the art can understand that Figure 6 the structure shown in
[0111] is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0111] In one embodiment, the resource loading device provided by the present application can be implemented in the form of a computer program, and the computer program can run on a computer device as Figure 6 shown. Each program module constituting the resource loading device can be stored in the memory of the computer device. For example, Figure 5 the loading module 310, the determination module 320, the retry module 330, and the display module 340 shown in
[0112] Figure 6 The computer device shown in Figure 5In the resource loading device shown, the loading module 310 executes to load the target resource corresponding to the resource loading request from multiple different resource storage units through the main thread when the middleware monitors a resource loading request corresponding to a target page, where the resource loading request is used to request the loading of the target resource. The computer device can execute, through the determination module 320, to determine, when the loading of the target resource fails in each of the resource storage units, a target retry scheme corresponding to the target resource according to the reason for the failure of loading the target resource. The computer device can execute, through the retry module 330, to re-obtain the target resource according to the target retry scheme by using an asynchronous thread. The computer device can execute, through the display module 340, to provide the target resource to the main thread for loading and display when the target resource is successfully obtained according to the target retry scheme.
[0113] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the resource loading method provided in any one of the foregoing method embodiments.
[0114] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0115] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution, in essence, or the part that contributes to the related technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, server 120, or network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0116] It should be understood that the terms used herein are for the purpose of describing particular example embodiments only and are not intended to be limiting. Unless the context clearly dictates otherwise, the singular forms "a", "an", and "the" as used herein may also include the plural forms. The terms "comprising", "including", "containing", and "having" are inclusive and thus specify the presence of stated features, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the particular order described or illustrated, unless the order of performance is explicitly stated. It should also be understood that additional or alternative.
[0117] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features claimed herein.
Claims
1. A resource loading method, characterized in that: The method comprises: When the middleware monitors a resource loading request corresponding to the target page, the target resource corresponding to the resource loading request is loaded from a plurality of different resource storage units through the main thread, wherein the resource loading request is used to request to load the target resource; When each of the resource storage units fails to load the target resource, determining a target retry scheme corresponding to the target resource according to a reason for the failure to load the target resource; Reacquire the target resource according to the target retry scheme using an asynchronous thread; When the target resource is successfully acquired according to the target retry scheme, the target resource is provided to the main thread for loading and display.
2. The method according to claim 1, characterized in that When the middleware monitors a resource loading request corresponding to the target page, the target resource corresponding to the resource loading request is loaded from a plurality of different resource storage units through the main thread, including: When the middleware monitors a resource loading request corresponding to the target page, the target resource corresponding to the resource loading request is quickly loaded from multiple different resource storage units through the main thread, wherein the multiple different resource storage units include a server and multiple different preset caches; After the target resource corresponding to the resource loading request is competitively loaded from a plurality of different resource storage units through the main thread, the method further includes: The target resource first loaded from a plurality of different resource storage units is provided to the main thread for loading and display.
3. The method according to claim 2, characterized in that After providing the target resource first loaded from the multiple different resource storage units to the main thread for loading and displaying, the method further includes: When the target resource loading source is a target cache, receiving a response result of the server to the resource loading request through a background, wherein the target cache is any preset cache; When the response result of the server to the resource loading request is a successful response, the target resource in the target cache is replaced with the target resource in the response result.
4. The method according to claim 1, characterized in that: Determining a target retry scheme corresponding to the target resource according to the reason for the failure to load the target resource includes: When the reason for the loading failure corresponding to the target resource is a network abnormality, a first retry scheme is determined as the target retry scheme, wherein the first retry scheme is used to send the resource loading request to the server when the target page is in a first network communication state, and if the target page fails to reacquire the target resource in the first network communication state, suspend reacquisition of the target resource and monitor the network change event corresponding to the target page; when it is monitored that the target page changes from the first network communication state to the second network communication state, the resource loading request is resent to the server, and the first network communication state and the second network communication state correspond to different communication modes; or, When the reason for the loading failure corresponding to the target resource is a server exception, a second retry scheme is determined as the target retry scheme, wherein the second retry scheme is used to obtain the target resource from a preset cache.
5. The method according to claim 1, characterized in that: After reacquiring the target resource using the asynchronous thread according to the target retry scheme, the method further includes: When the target resource cannot be acquired by using the asynchronous thread, determining the cumulative number of retries; Determine a preset number of retries according to the network status of the target page; When the cumulative number of retries is less than the preset number of retries, the target retry scheme corresponding to the target resource is determined again according to the reason for the failure to load the target resource, and the target resource is re-acquired according to the target retry scheme using an asynchronous thread.
6. The method according to claim 5, characterized in that Determining a preset number of retries according to the network status of the target page, when the target resource acquisition by using the asynchronous thread fails includes: When the network status of the target page is a low-speed network, determining a first preset number of times as the preset number of retries; When the network status of the target page is a high-speed network, a second preset number of times is determined as the preset number of retries, wherein the first preset number of times is less than the second preset number of times.
7. The method according to claim 1, characterized in that When the middleware monitors a resource loading request corresponding to the target page, the target resource corresponding to the resource loading request is loaded from a plurality of different resource storage units through the main thread, including: When the middleware monitors multiple resource loading requests corresponding to the target page, the response priority of each resource loading request is determined according to the resource type corresponding to each resource loading request; According to the response priority corresponding to each resource loading request, the target resources corresponding to each resource loading request are loaded from multiple different resource storage units in sequence through the main thread.
8. A resource loading device, characterized in that: The device comprises: A loading module, used for loading target resources corresponding to the resource loading request from multiple different resource storage units through a main thread when the middleware monitors a resource loading request corresponding to the target page, wherein the resource loading request is used to request to load the target resource; A determination module, configured to determine a target retry scheme corresponding to the target resource according to a reason for the failure to load the target resource when each of the resource storage units fails to load the target resource; A retry module, used to reacquire the target resource according to the target retry scheme using an asynchronous thread; The display module is used to provide the target resource to the main thread for loading and display when the target resource is successfully acquired according to the target retry scheme.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.