Webpage white screen optimization method and device, terminal equipment and storage medium
Through the network view webview interceptor and interface-level caching tools to intercept and use cached data for web page rendering, it solves the problem of long white screen time in different application scenarios and achieves page loading efficiency and data integrity.
Patent Information
- Application Number
- CN202410828171.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-08-30
AI Technical Summary
Existing technology cannot effectively reduce the white screen time of web pages in different application scenarios. Especially when the network conditions are poor or resource loading is delayed, users will still see a blank screen until the page resources are completely loaded.
Intercept the browser's request through the webview interceptor and/or interface-level caching tool, check whether the request has been cached, and if so, use the cached data for page rendering and data rendering, and update the cached data when necessary to ensure the timeliness of the data. sex.
This solution combines the client's webview layer interceptor with interface-level caching tools to intercept and cache management for different request types, making the loading time of various pages as low as possible, reducing the user's white screen time and waiting time for data loading, and ensuring Page data integrity.
Smart Images

Figure CN118568374A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer application technology, and in particular to a web page white screen optimization method, device, terminal device and storage medium. Background Art
[0002] White screen usually occurs when a web page is loading, especially in poor network conditions or when resource loading is delayed. Users will see a blank screen until the page resources are fully loaded.
[0003] At present, there are two common white screen optimization methods. One is to use the service worker API (service worker application program interface) as a request agent between the browser and the web server. When the browser sends a request, the service worker can intercept it and decide whether to return the buffer or continue the request. When the web server returns the web resource information, the service worker can decide whether to cache this information, thereby optimizing the loading of web pages and reducing the white screen phenomenon. However, different versions and manufacturers of Webview (network view) support Service Worker to different degrees, which may cause some optimization measures to fail to take effect on some devices. The second is to pre-fill the loading status data or skeleton diagram in the request for priority rendering, reducing the white screen waiting when the actual business data is returned, but it is still information with no actual business significance.
[0004] In summary, the current white screen optimization method still cannot solve the problem of reducing the white screen time of various web pages as much as possible in different application scenarios. Summary of the invention
[0005] The main purpose of the present application is to provide a web page white screen optimization method, device, terminal device and storage medium, aiming to solve the technical problem of reducing the white screen time of various web pages as much as possible in different application scenarios.
[0006] To achieve the above purpose, the present application proposes a web page white screen optimization method, the method comprising: According to the type of the request, intercepting the request sent by the browser by a webview interceptor and / or an interface-level cache tool; Checking whether the request has been cached in a cache database by the webview interceptor and / or the interface-level cache tool; If so, the cached data in the database is used to complete the page rendering and / or data rendering.
[0007] In one embodiment, the step of intercepting the request sent by the browser by a webview interceptor and / or an interface-level cache tool according to the type of the request includes: If the type of the request is a static resource request, the request initiated by the browser is intercepted by the webview interceptor; If the type of the request is a dynamic resource request, the request initiated by the browser is intercepted by an interface-level cache tool.
[0008] In one embodiment, the step of checking whether the request has been cached in the database by a webview interceptor and / or an interface-level cache tool comprises: If the type of the request is a static resource request, check whether the static resource request has been cached in the database through the webview interceptor; If the type of the request is a dynamic resource request, then an interface-level cache tool is used to check whether the dynamic resource request has been cached in the database.
[0009] In one embodiment, the step of checking whether the static resource request has been cached in the cache database through the webview interceptor includes: Comparing the address information of the static resource request with the address information cached in the database; If the address information of the static resource request is consistent with the address information cached in the database, it means that the static resource request has been cached in the database; If the address information of the static resource request is inconsistent with the address information cached in the database, it means that the static resource request is not cached in the database.
[0010] In one embodiment, if the type of the request is a dynamic resource request, the step of checking whether the dynamic resource request has been cached in the database through an interface-level cache tool comprises: Calculate the address information and parameters of the dynamic resource request to obtain a key of the dynamic resource request; Compare the key of the dynamic resource request with the key in the database; If the key of the dynamic resource request is consistent with the key in the database, it means that the dynamic resource request has been cached in the database; If the key of the dynamic resource request is inconsistent with the key in the database, it means that the dynamic resource request is not cached in the database.
[0011] In one embodiment, the step of using cached data in the database to accelerate page rendering and / or data rendering includes: The cached data is sent to the browser through the webview interceptor so that the browser can render the page. At the same time, the request is sent to the server through the webview interceptor to obtain the latest request information; Receive the latest request information returned by the server; Perform hash value calculation on the latest request information and the cached data in the database to obtain the hash value of the latest request information and the hash value of the cached data in the database; Compare the hash value of the latest request information with the hash value of the cached data in the database to see if they are consistent; If not, the webview interceptor is used to trigger the refresh page logic processing so that the browser can refresh and render the page; and / or The cached data in the database is returned to the browser through an interface-level cache tool so that the browser can render the data.
[0012] In one embodiment, before the step of using cached data in the database to accelerate page rendering and / or data rendering, the method further includes: Based on a preset time condition, performing a data validity check on the cached data in the database; Clear cached data that does not meet the data validity period; and / or Checking the survival time of the cached data; If the survival time of the cached data meets a preset threshold, the cached data is directly deleted.
[0013] In one embodiment, after the step of sending the cached data in the database to the browser for page rendering and / or data rendering, the method further includes: If not, the request is sent to the server through the webview interceptor to obtain the latest request information; Receive the latest request information returned by the server; Performing a whitelist check on the address information in the latest request information; caching the latest request information that has passed the whitelist verification, and sending the latest request information to the browser for the browser to render the page; and / or Cache the request through an interface-level cache tool, send the request to the server, and wait for the server to return a response; When a response returned by the server is received, the response is cached and sent to the browser for the browser to render data.
[0014] In addition, to achieve the above purpose, the present application also proposes a web page white screen optimization device, the web page white screen optimization device comprising: A request interception module is used to intercept requests sent by the browser according to the type of request through a webview interceptor and / or an interface-level cache tool; A cache checking module, used to check whether the request has been cached in the cache database through a webview interceptor and / or an interface-level cache tool; The cache processing and updating module is used to send the cache data in the database to the browser for page rendering and / or data rendering.
[0015] In addition, to achieve the above-mentioned purpose, the present application also proposes a web page white screen optimization terminal device, the device comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the web page white screen optimization method as described above.
[0016] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the web page white screen optimization method described above are implemented.
[0017] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the web page white screen optimization method described above are implemented.
[0018] The present application provides a web page white screen optimization method, which intercepts the request sent by the browser according to the type of request through the webview interceptor and / or the interface-level cache tool; checks whether the request has been cached in the database through the webview interceptor and / or the interface-level cache tool; if so, sends the cached data in the database to the browser for page rendering and / or data rendering. This solution intercepts different requests through the interceptor of the webview layer of the client combined with the interface-level cache tool, and sends the cached data to the browser for rendering operations, so that the loading time of various pages is as low as possible, and the page data is guaranteed to be complete, effectively reducing the user's white screen time and waiting time for data loading. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0021] Figure 1 A flowchart diagram of the first embodiment of the web page white screen optimization method of the present application; Figure 2 A flowchart diagram of the second embodiment of the web page white screen optimization method of the present application; Figure 3 This is an overview of the top-level structure of the page-level cache based on the webview interceptor involved in the web page white screen optimization method in the embodiment of the present application; Figure 4 This is a logic diagram of first access client request interception and cache refresh involved in the web page white screen optimization method in the embodiment of the present application; Figure 5 This is the logic diagram of secondary access client request interception and cache refresh involved in the web page white screen optimization method of this application; Figure 6 A schematic diagram of the interface optimization process of the interface-level cache tool involved in the web page white screen optimization method of this application; Figure 7 This is a logic diagram of the interaction between the client and the server in the server rendering mode involved in the application scenario example of the web page white screen optimization method of this application; Figure 8 A simple flow chart of page data caching and rendering in the server-side rendering mode involved in the application scenario example of the web page white screen optimization method of this application; Fig. 9 This is a logic diagram of the interaction between the client and the server in the client rendering mode involved in the application scenario example of the web page white screen optimization method of this application; Fig.10 This is a white screen data trend chart of the personal homepage after the first optimization in the server-side rendering mode involved in the application scenario example of the web page white screen optimization method of this application; Fig.11 This is a white screen data trend chart after the user cache of the personal homepage in the server-side rendering mode involved in the application scenario example of the web page white screen optimization method of this application is stabilized; Fig.12 This is a white screen data trend chart of the discussion area page after the first optimization in the client rendering mode involved in the application scenario example of the web page white screen optimization method of this application; Fig.13This is a white screen data trend chart after the user cache of the discussion area in the client rendering mode involved in the application scenario example of the web page white screen optimization method of this application is stabilized; Fig.14 This is a schematic diagram of the module structure of the web page white screen optimization device according to an embodiment of the present application; Fig.15 Schematic diagram of the device structure of the hardware operating environment involved in the web page white screen optimization method in the embodiment of the present application.
[0022] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0023] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0024] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0025] The main solution of the embodiment of the present application is to intercept the request sent by the browser according to the type of request through the webview interceptor and / or the interface-level cache tool; check whether the request has been cached in the database through the webview interceptor and / or the interface-level cache tool; if so, send the cached data in the database to the browser for page rendering and / or data rendering.
[0026] White screen usually occurs when a web page is loading, especially in poor network conditions or when resource loading is delayed. Users will see a blank screen until the page resources are fully loaded.
[0027] At present, common white screen optimization methods can be divided into two types. First, the service worker API can exist as an agent between the browser and the web server. When the browser initiates a request, the service worker can intercept it and decide whether to abandon the return cache or continue the request. When the web server returns the web resource information, the service worker can decide whether to cache this data. However, due to the fragmentation of webview versions supported on mobile phones, some optimization measures may not take effect on some devices. Second, fill the loading status data or skeleton diagram in the request in advance for priority rendering, reducing the white screen waiting when the actual business data is returned, but it is still information with no actual business significance.
[0028] In summary, the current white screen optimization method still cannot solve the problem of reducing the white screen time of various web pages as much as possible in different application scenarios.
[0029] This application provides a solution that uses the client webview on the upper layer of the web to replace the intermediate proxy function of the service worker, intercepting requests initiated by the browser, making the system more compatible, allowing the white screen optimization method to cover more users, and completely caching page information. And combined with the interface-level cache tool, it can ensure that static resources and asynchronous interface data can reach the cache-level speed response, reducing the user's white screen time and waiting time for data loading.
[0030] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a mobile phone, a cell phone, etc., or an electronic device capable of realizing the above functions, etc. The following takes a cell phone as an example to illustrate this embodiment and the following embodiments.
[0031] Based on this, the embodiment of the present application provides a web page white screen optimization method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the web page white screen optimization method of the present application.
[0032] In this embodiment, the webpage white screen optimization method includes steps S10 to S40: Step S10, intercepting the request sent by the browser through a webview interceptor and / or an interface-level cache tool according to the type of the request; It should be noted that the types of requests include static resource requests and dynamic resource requests.
[0033] A webview interceptor refers to a mechanism set up at the Webview level that allows developers to intercept and process requests before they are actually sent to the server.
[0034] The interface-level cache tool is mainly used for optimizing dynamic data requests. It is implemented in the front-end logic of the application and can be an independent library, such as Redux Offline, axios cache plug-in, or a custom cache strategy. This embodiment takes the axios-cache tool as an example.
[0035] Based on the above, in a feasible implementation, step S10 may include steps S11-S12: Step S11, if the type of the request is a static resource request, intercepting the request initiated by the browser through the webview interceptor; It should be noted that static resource requests refer to content that is directly returned by the server and does not change with the user or time, such as HTML, CSS, JavaScript files, images, videos, etc.
[0036] In addition, it should be noted that due to the different support levels of webAPI for various models, this application uses the webview on the upper layer of the web to replace the intermediate proxy function of the service worker in the prior art. The webview interceptor is a component embedded inside the client that can monitor and intervene in all network requests initiated from the web. When the browser initiates a request to the web server, and the request is a static resource request, the client's webview interceptor will intercept the request so that the request can be subsequently cached at the page level.
[0037] Step S12: If the type of the request is a dynamic resource request, the request initiated by the browser is intercepted by an interface-level cache tool.
[0038] It should be noted that dynamic resource requests involve server-side calculations or database queries, and the returned content will change according to the user's specific request or status, such as user personal information, real-time data, search results, etc.
[0039] In addition, it should be noted that this embodiment provides an axios-cache tool for interface-level caching, which is executed in the browser module throughout the process. Relative to the page-level cache of the client's webview interceptor described in the above step S11, the interface-level cache tool can be used as a supplement to the overall cache solution, and the combination of static resources and asynchronous interface data can achieve cache-level speed response.
[0040] Through the above steps, you can select appropriate webview interceptors and / or interface machine cache tools for interception according to different request types, providing a key foundation for the subsequent implementation of more efficient resource management and caching strategies.
[0041] Step S20, checking whether the request has been cached in the cache database through the webview interceptor and / or the interface-level cache tool; The interface-level caching tool and / or webview interceptor intercepts the request before it is actually sent to the server and checks whether the request is necessary. The Webview interceptor and / or interface-level caching tool caches the request to improve the application response speed, reduce network traffic consumption, and improve the user experience.
[0042] In order to better explain step S20, in this embodiment, step S20 also includes steps S21-S22: Step S21, if the type of the request is a static resource request, checking whether the static resource request has been cached in the database through the webview interceptor; When the Webview interceptor identifies a static resource request, it can decide whether to allow the static resource request to continue to the server, or whether to use locally cached data to respond to the static resource request.
[0043] In a feasible implementation, step S21 may include steps A1 to A3: Step A1, comparing the address information of the static resource request with the address information cached in the database; In order to confirm whether the static resource currently requested has been stored in the cache record in the database, this can be achieved by directly comparing the resource URL in the request, that is, the address information, with all the cache resource URLs recorded in the database. The database may include SQLite (micro-Lite database), Realm (domain database), etc.
[0044] Specifically, the client can propose the complete URL of the static resource from the request initiated by the browser, and then query whether there is a matching record in the database. Among them, the query is usually based on the URL as a keyword, because the URL is the address that uniquely identifies a network resource.
[0045] Step A2: if the address information of the static resource request is consistent with the address information cached in the database, it means that the static resource request has been cached in the database; If it is found that the requested static resource URL is exactly the same as a URL recorded in the database cache, it means that the static resource request has been processed by a previous request and its content has been saved in the cache table of the database.
[0046] Step A3: If the address information of the static resource request is inconsistent with the address information cached in the database, it means that the static resource request is not cached in the database.
[0047] When the requested static resource URL does not find a match in the database cache, it indicates that the static resource request has not been cached, or the cache has expired and been removed.
[0048] Step S22: If the type of the request is a dynamic resource request, then checking whether the dynamic resource request has been cached in the database through an interface-level cache tool.
[0049] When a dynamic resource request is triggered, the interface-level cache tool will first check whether the dynamic resource request has been cached in the database and whether the data is still valid (not expired). The database may include LocalStorage (local cache), IndexedDB (index database), etc.
[0050] In a feasible implementation, step S22 may include steps B1 to B4: Step B1, calculating the address information and parameters of the dynamic resource request to obtain a unique identification key of the dynamic resource request; Dynamic resource requests usually contain URLs and parameters, which may affect the data content returned by dynamic resource requests. In order to determine whether a dynamic resource request has been cached, an identifier that can uniquely represent the request and its parameters is required. The address information and all parameters of the dynamic resource request can be combined and calculated through a hash function to generate a unique key value.
[0051] Step B2, comparing the key of the dynamic resource request with the key in the database; After calculating the unique identification key of the dynamic request, the next step is to check whether there is a matching record in the database.
[0052] The client will query the specific cache table in the database to see if there is a record with the same calculated key value. This query process is based on an exact match of the key value.
[0053] Step B3: if the key of the dynamic resource request is consistent with the key in the database, it means that the dynamic resource request has been cached in the database; If the key of the dynamic resource request finds a matching key in the database, it means that the same dynamic request has been executed before and its result has been cached.
[0054] Step B4: If the key of the dynamic resource request is inconsistent with the key in the database, it means that the dynamic resource request is not cached in the database.
[0055] If the key of the dynamic resource request does not find a matching key in the database, it means that this specific dynamic request and its parameter combination have not been cached before, or the cache has expired.
[0056] Through the above steps, by comparing the request address with the database cache record in real time, the system can intelligently decide whether to use the data in the cache or initiate a new network request, thereby maximizing resource utilization efficiency while ensuring data timeliness.
[0057] Step S30: If yes, use the cached data in the database to complete page rendering and / or data rendering; It should be noted that page rendering refers to the process of converting a web page's HTML (HyperText Markup Language), CSS (Cascading Style Sheets), JavaScript and other source code into an interactive visual interface that users can see in a browser.
[0058] Data rendering refers to the process of page rendering, which pays special attention to how to insert dynamic data (usually data obtained from the server or generated by user interaction) into the HTML document so that the page content can be dynamically updated as the data changes.
[0059] In a feasible implementation, step S30 may include steps S31 to S36: Step S31, sending the cached data to the browser through the webview interceptor for the browser to render the page, and at the same time, sending the request to the server through the webview interceptor to obtain the latest request information; When a user requests to load a page, webview does not directly pull data from the server first, but checks whether there is cached data of the webpage in the local database through its built-in interceptor. If it exists, the webview interceptor will first return the cached data to the browser for page rendering. While providing cached data to the browser, the webview interceptor will continue to send requests to the server to obtain the latest version of the page or verify the validity of the current cache. This is done to facilitate the browser to update or verify data and ensure the freshness of the content.
[0060] Step S32, receiving the latest request information returned by the server; It should be noted that, in this embodiment, the latest request information may refer to the HTML returned by the server.
[0061] When the server responds to the interceptor's request, it returns the HTML of the page to the client.
[0062] Step S33, performing hash value calculation on the latest request information and the cached data in the database to obtain the hash value of the latest request information and the hash value of the cached data in the database; In order to efficiently determine whether the data cached in the local database is expired, the client will calculate the hash values of the HTML and the cached data in the local database. The hash value is a fixed-length digital fingerprint generated based on the data content. Even a small change in the data will result in a huge difference in the hash value.
[0063] Step S34, comparing the hash value of the latest request information with the hash value of the cached data in the database to see if they are consistent; By comparing the hash value of the HTML with the hash value of the cached data in the local database, it is possible to quickly determine whether the cached content in the local database is consistent with the HTML returned by the server.
[0064] Step S35, triggering the logic processing of refreshing the page through the webview interceptor, so that the browser can refresh and render the page; and / or If the hash value of the html is inconsistent with the hash value of the cached data in the local database, it means that there is new content in the latest request information returned by the server. Then the client's webview triggers the page refresh logic. The browser uses the html file to refresh the page based on the page refresh logic and re-renders the page to ensure that the user sees the latest information.
[0065] Step S36, returning the cached data in the database to the browser through the interface-level cache tool, so that the browser can render the data.
[0066] In addition to the above steps, that is, caching the cached data through the client and returning it to the browser for the browser to refresh and render the page, the cached data in the local database can also be returned directly to the browser for data rendering through the interface-level cache tool, and the cached data on the page can be refreshed to the latest response data returned by the server.
[0067] Through the above steps, combined with the webview interceptor and interface-level caching tools, it is ensured that both static resource data and dynamic resource data can achieve fast response at the cache level, ensuring that users obtain the latest content while maximizing the use of cache advantages, reducing the impact of network delays, and improving user experience.
[0068] In another feasible implementation manner, after step S30, steps C1 to C6 may also be included: It should be noted that if a webview interceptor and / or an interface-level cache tool is used to check that the request is not cached in the database, the request is forwarded to the server to obtain the latest request information, and the latest request information is cached.
[0069] Specifically, in step C1, if not, the request is sent to the server through the webview interceptor to obtain the response data returned by the server; When a user visits a page for the first time, since the system does not have cached data for the page, the webview interceptor will directly send the request to the server for the server to analyze the request and obtain the corresponding response data.
[0070] Step C2, receiving the response data returned by the server; After processing the request, the server returns response data to the client, where the response data may include HTML, JSON, etc.
[0071] Step C3, performing a whitelist check on the address information in the response data through a webview interceptor; Before using the response data, the client's webview interceptor will perform security checks on the address information in the data, which may be resource links, redirect URLs, etc., to ensure that these addresses come from pre-set trusted sources, namely the whitelist. This is to prevent malicious injection or loading of unauthorized resources and increase the security of the application.
[0072] Step C4, caching the response data that passes the whitelist check, and sending the response data to the browser for the browser to render the page; and / or The response data that passes the whitelist check will be stored in the local cache so that subsequent similar requests can be quickly extracted directly from the cache, reducing network requests and improving response speed. The checked and cached response data is then passed to the browser engine to build and display page content to the user.
[0073] Response data that does not pass the whitelist check will be directly returned to the browser for display.
[0074] Step C5, caching the request through an interface-level cache tool, sending the request to the server, and waiting for response data returned by the server; In addition to the page caching method through the webview interceptor, this embodiment can also provide an interface-level caching tool to cache dynamic resource data.
[0075] When the interface-level cache tool detects that the page request does not exist in the local database, it sends the request to the server and waits for the server to return the response data.
[0076] Step C6, when the response data returned by the server is received, the response data is cached and sent to the browser for the browser to render the data.
[0077] When the server returns the response data, it caches the response data itself and returns it to the browser for data rendering.
[0078] The above steps not only ensure the security of data, but also use a multi-level caching strategy, that is, combining the webview interceptor-level and interface-level caching tools to perform efficient cache management on page-level static resource cache and dynamic resource cache respectively, which significantly improves the performance of the application and user experience, while reducing dependence on external servers and improving data loading efficiency.
[0079] Through the above-mentioned embodiment method, the request sent by the browser is intercepted according to the type of request through the webview interceptor and / or the interface-level cache tool; through the webview interceptor and / or the interface-level cache tool, it is checked whether the request has been cached in the database; if so, the cached data in the database is sent to the browser for page rendering and / or data rendering. This solution intercepts different requests through the interceptor of the webview layer of the client combined with the interface-level cache tool, and sends the cached data to the browser for rendering operations, so that the loading time of various pages is as low as possible, and the page data is guaranteed to be complete, effectively reducing the user's white screen time and waiting time for data loading.
[0080] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 Before step S30, the webpage white screen optimization method further includes steps S301 to S304: Step S301, based on a preset time condition, performing a data validity check on the cached data in the database; Before considering using cached data, the client will check the validity of the cached data based on preset time conditions, such as the creation time or last update time of the cached data, and the preset expiration time. If the cached data has exceeded its validity period, it may no longer reflect the latest status on the server, and continued use may result in incorrect or inconsistent information.
[0081] Step S302, clearing cached data that does not meet the data validity period.
[0082] For cached data that is found to be expired or does not meet the validity conditions after inspection, the system will perform a cleanup operation to remove the invalid data from the database.
[0083] Step S303, checking the survival time of the cached data; Since the preset time condition is a cache data clearing condition set for the client, but the interface-level cache tool is a tool set in the browser module, the present application also proposes to dynamically monitor the "survival time" of each cache data item through the interface-level cache tool, that is, the length of time since the cache data was created or last accessed.
[0084] Step S304: if the survival time of the cached data meets a preset threshold, the cached data is directly deleted.
[0085] If it is detected that the survival time of a cached data has reached a pre-set threshold, such as the data has exceeded a certain number of days or hours since it was created or last accessed, the system will automatically perform a deletion operation to remove the cached data that is deemed no longer necessary.
[0086] The above-mentioned embodiment method helps to keep the database clean, avoid problems caused by using obsolete data, and release storage space to reserve space for new cache.
[0087] For example, to help understand the implementation process of the web page white screen optimization method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 3 , Figure 3 An overview diagram of the top-level structure of the page-level cache based on the webview interceptor involved in the web page white screen optimization method is provided, specifically: Since the support of web API varies from device to device, this implementation replaces the intermediate proxy function of service worker by modifying the client webview of the upper layer of web. This method is non-invasive to web pages, so web developers do not need to consider the details of cache, and only need to add the address data of the page to be cached in the cache whitelist interface data.
[0088] It should be noted that the focus of this embodiment is on the white screen optimization of page rendering, so the target file for optimization can be summarized in the HTML file, because HTML is the first file returned by a web application request. When the browser initiates an HTML request, the client's webview will intercept the request.
[0089] like Figure 4 As shown, Figure 4 Logic diagram for intercepting client requests and refreshing cache for the first time.
[0090] Specifically, when a user visits a page for the first time, since there is no cached data in the system, when the browser sends a request to the web server, it will send the request directly to the web server. After the web server returns the HTML data, the page address will be whitelisted, and the page address that passes the whitelist verification will be cached, and the HTML will be returned to the browser for page rendering; the page address that does not pass the whitelist verification will be directly returned to the browser for page rendering.
[0091] like Figure 5 As shown, Figure 5 Logic diagram for intercepting client requests and refreshing cache for secondary access.
[0092] When the user visits the page for the second time, the webview interceptor will give priority to returning the cached HTML data to the browser for display, and let the request continue to be sent to the web server. When the web server returns the latest HTML information, the cached HTML and the HTML returned by the server are hashed, and the hash values are compared to check whether the HTML is consistent. If they are consistent, the process ends. If they are inconsistent, the logic of refreshing the web page is triggered, the web page is reloaded, and this logic is repeated to apply the latest cache.
[0093] It should be noted that since each cached data has an expiration period, the validity period of all cached data will be checked after the app is started. If the expiration period exceeds this period, the cache will be automatically cleared to prevent the cache from taking up too much space over time.
[0094] Through the above-mentioned embodiment method, the page-level caching method webview interceptor can give priority to displaying cached pages, and then refresh the cached pages as needed, so as to display the HTML page to the user as soon as possible and reduce the white screen time.
[0095] For example, to help understand the implementation process of the web page white screen optimization method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 6 , Figure 6 A schematic diagram of an interface optimization process of an interface-level cache tool is provided, specifically: This embodiment provides an axios-cache tool for interface-level caching. Compared with the page-level caching of the webview interceptor in Embodiment 2, they complement each other in the overall caching solution, and their combined use ensures that both static resources and asynchronous interface data can achieve cache-level speed response.
[0096] The axios-cache tool is based on axios and has been extended. After the page sends a data request, the tool will intercept the interface request and first check whether there is cached data for the interface request. If there is, the cached data will be immediately returned to the page display through the axios-cache tool, and the original interface request will continue to execute to the server and wait for the server response. The new data returned by the server is not only used to update the page immediately (replacing the previous cached data display), but will also be stored in the cache to refresh the cached data on the page to the latest server data. Through this process, the data can be filled into the HTML as quickly as possible and displayed to the user.
[0097] Through the above-mentioned embodiment method, the interface-level cache tool axios-cache is used to display cached data first, and then the actual data refreshes the cached data, so as to obtain data for display as soon as possible and reduce the time users wait for data loading.
[0098] In order to better understand the solution of the present application, the embodiment method of the present application is described in detail below in combination with specific application scenarios.
[0099] The existing web rendering modes are roughly divided into three categories: server-side pre-rendering, server-side rendering, and client-side rendering. The present application method can optimize the page white screen situation generated in the above three web rendering modes.
[0100] Specifically, the page in the server-side pre-rendering mode generally displays static data, and the static HTML file of the complete data is immediately returned to the browser for display to the user, so it is only necessary to cache the static HTML file through the client's webview interceptor and refresh the cache through the hash verification mechanism.
[0101] In the server-side rendering mode, in order to make the data in the HTML file as complete as possible, it is generally related to business information and user information. Therefore, it is necessary to prepare the complete data required by the page as much as possible on the web server and return it to the client for caching, so as to speed up the loading of the complete HTML for the next visit. Figure 7 As shown, Figure 7 This is a logical diagram of the interaction between the client and the server in server-side rendering mode.
[0102] When a user visits a first-level page for the first time, this embodiment uses cookies (small text files) to store user information tokens (access tokens), so that all second-level pages under the same domain name can share tokens, saving the user permission verification process. Business information is usually placed behind the link as a parameter. The web server obtains the token in the cookie and the params (parameters) in the URL, and calls the backend service to obtain the business and user data required by the html. Because the data in the html will be cached by the webview interceptor, if the cached data changes frequently, it will cause the page to refresh frequently, reducing the user's page access experience.
[0103] For static resource requests of HTML pages, you can use the client's webview interceptor to cache HTML and refresh the cache through a hash verification mechanism. For asynchronous data of the page (i.e. dynamic resource requests), the asynchronous data of the page can be divided into real-time changing data and non-real-time changing data.
[0104] like Figure 8 As shown, Figure 8 This is a simple flow chart for caching and rendering page data in server-side rendering mode. Since non-real-time changing data has a lower cache refresh requirement, the data can be prepared in advance and assembled into HTML to provide cache. For real-time changing data, the axios-cache tool is used to perform interface-level caching to ensure the integrity of page data, thereby achieving the final HTML white screen optimization.
[0105] For a page in client rendering mode, after being cached by the client's webview, since its initial HTML has no substantial rendering content and the file size is small, the existing inline plug-ins on the market can be used to inline CSS (Cascading StyleSheets) files into HTML, saving the request and response time of CSS static resources. And, as the general method says, add a loading state or skeleton diagram to optimize the white screen experience of the first visit to the page. In order to improve the existing method and enable the complete data to be cached by the webview interceptor, this application proposes a process to cache the complete page in this mode. Fig. 9 As shown, Fig. 9 This is the interaction logic diagram between the client and the server in client rendering mode.
[0106] Specifically, by calling the webview API in a bridged manner through js (JavaScript) in the page onload (loading completion) event to cache the HTML data that has been fully rendered on the client, rather than returning to the client stage for caching, the full HTML data can be cached. After the full cache is completed, the user can load the complete HTML data first the next time he visits, but the HTML request will still go to the web server and obtain an empty HTML with no rendered content. And by setting a hidden flag (invisible to the user) in the HTML header (the header area of the document or section), the webview parses the flag after obtaining the HTML data responded by the web server to determine whether it is necessary to refresh the page to update the cache.
[0107] For real-time changing data and non-real-time changing data on the page, in this client rendering mode, the page script will obtain the backend server business, user and other data as usual and update it to the HTML page without additional modification and adaptation.
[0108] In order to better understand the effective effects that can be achieved by adopting the solution of the present application for the above-mentioned application scenarios, the following takes pages in server-side rendering mode and client-side rendering mode as examples.
[0109] Please refer to Fig.10 , Fig.10 This is the white screen data trend chart of the personal homepage after the first optimization in server-side rendering mode. Fig.10 It can be seen that according to the statistical data on the in-line performance test platform, through the cache optimization of this solution, the white screen time has been reduced from the original maximum of about 750ms to 450ms. With the gradual coverage of the page cache, it will eventually be fixed at about 320ms. Please refer to Fig.11 , Fig.11 The white screen data trend chart after the user cache of the personal homepage in the server-side rendering mode is stabilized. Fig.11 It can be seen that after the page cache is overwritten, the white screen data finally freezes at 300ms, and there is only a slight fluctuation trend.
[0110] Please refer to Fig.12 , Fig.12 This is the white screen data trend chart after the first optimization of the discussion forum page in client rendering mode. Fig.12 It can be seen that according to the statistical data on the in-line performance test platform, through the application of the above-mentioned client page-level cache and the gradual coverage of the page cache, the final frame is fixed at about 289ms. Fig.13 , Fig.13 The white screen data trend chart is cached and stabilized for users in the discussion forum in client-side rendering mode. Fig.13It can be seen that when the page cache is overwritten, the white screen data finally freezes at around 289ms, and there is only a slight fluctuation trend.
[0111] Through the above examples of different application scenarios, for the three page rendering modes of client rendering mode, server rendering mode, and server pre-rendering mode, the interceptor of the client's webview layer combined with the interface-level caching tool is used to intercept different requests, and the cached data is sent to the browser for rendering operations, so that the loading time of various pages is as low as possible, and the page data is guaranteed to be complete, effectively reducing the user's white screen time and waiting time for data loading.
[0112] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the web page white screen optimization method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.
[0113] This application also provides a web page white screen optimization device, please refer to Fig.14 , the web page white screen optimization device comprises: The request interception module 10 is used to intercept the request sent by the browser according to the type of request through the webview interceptor and / or the interface level cache tool; The cache checking module 20 is used to check whether the request has been cached in the cache database through a webview interceptor and / or an interface-level cache tool; The cache processing and updating module 30 is used to send the cache data in the database to the browser for page rendering and / or data rendering.
[0114] The webpage white screen optimization device provided by the present application adopts the webpage white screen optimization method in the above embodiment, which can solve the technical problem of making the white screen time of various webpages as short as possible in different application scenarios. Compared with the prior art, the beneficial effects of the webpage white screen optimization device provided by the present application are the same as the beneficial effects of the webpage white screen optimization method provided by the above embodiment, and the other technical features in the webpage white screen optimization device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0115] The present application provides a web page white screen optimization terminal device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the web page white screen optimization method in the above-mentioned embodiment one.
[0116] Reference below Fig.15, which shows a schematic diagram of the structure of a web page blank screen optimization terminal device suitable for implementing the embodiment of the present application. The web page blank screen optimization terminal device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, mobile phones, etc. Fig.15 The web page white screen optimization terminal device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0117] like Fig.15 As shown, the web page white screen optimization terminal device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the web page white screen optimization terminal device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the webpage white screen optimization terminal device to communicate wirelessly or wired with other devices to exchange data. Although the webpage white screen optimization terminal device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided alternatively.
[0118] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0119] The webpage white screen optimization terminal device provided by the present application adopts the webpage white screen optimization terminal method in the above embodiment, which can solve the technical problem of making the white screen time of various webpages as short as possible in different application scenarios. Compared with the prior art, the beneficial effects of the webpage white screen optimization terminal device provided by the present application are the same as the beneficial effects of the webpage white screen optimization method provided by the above embodiment, and the other technical features in the webpage white screen optimization terminal device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0120] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0121] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0122] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the web page white screen optimization method in the above-mentioned embodiment.
[0123] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0124] The above-mentioned computer-readable storage medium may be included in the web page white screen optimization terminal device; or it may exist independently without being assembled into the web page white screen optimization terminal device.
[0125] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the web page white screen optimization terminal device, the web page white screen optimization terminal device: intercepts the request sent by the browser through the network view webview interceptor and / or the interface-level cache tool according to the type of the request; checks whether the request has been cached in the database through the webview interceptor and / or the interface-level cache tool; if so, uses the cached data in the database to complete page rendering and / or data rendering; if not, forwards the request to the server to obtain the response data returned by the server, and caches the response data returned by the server.
[0126] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0127] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0128] The modules involved in the embodiments of the present application may be implemented by software or hardware, wherein the name of the module does not limit the unit itself in some cases.
[0129] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned web page white screen optimization method, and can solve the technical problem of making the white screen time of various web pages as short as possible in different application scenarios. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the web page white screen optimization method provided by the above-mentioned embodiment, and will not be repeated here.
[0130] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned web page white screen optimization method when executed by a processor.
[0131] The computer program product provided by this application can solve the technical problem of reducing the white screen time of various web pages as much as possible in different application scenarios. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the web page white screen optimization method provided by the above embodiment, and will not be repeated here.
[0132] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A web page white screen optimization method, characterized in that: The method comprises: Intercept the requests sent by the browser based on the type of request using a webview interceptor and / or an interface-level cache tool; Checking whether the request has been cached in the database by the webview interceptor and / or the interface-level cache tool; If so, the cached data in the database is sent to the browser for page rendering and / or data rendering.
2. The webpage white screen optimization method according to claim 1, characterized in that: The types of the requests include static resource requests and dynamic resource requests, and the step of intercepting the request sent by the browser according to the type of the request by using a webview interceptor and / or an interface-level cache tool includes: If the type of the request is a static resource request, the request initiated by the browser is intercepted by the webview interceptor; If the type of the request is a dynamic resource request, the request initiated by the browser is intercepted by an interface-level cache tool.
3. The webpage white screen optimization method according to claim 1, characterized in that: The step of checking whether the request has been cached in the database by the webview interceptor and / or the interface-level cache tool comprises: If the type of the request is a static resource request, check whether the static resource request has been cached in the database through the webview interceptor; If the type of the request is a dynamic resource request, then an interface-level cache tool is used to check whether the dynamic resource request has been cached in the database.
4. The webpage white screen optimization method according to claim 3, characterized in that: The step of checking whether the static resource request has been cached in the database through the webview interceptor includes: Comparing the address information of the static resource request with the address information cached in the database; If the address information of the static resource request is consistent with the address information cached in the database, it means that the static resource request has been cached in the database; If the address information of the static resource request is inconsistent with the address information cached in the database, it means that the static resource request is not cached in the database.
5. The webpage white screen optimization method according to claim 3, characterized in that: If the type of the request is a dynamic resource request, the step of checking whether the dynamic resource request has been cached in the database through an interface-level cache tool comprises: Calculate the address information and parameters of the dynamic resource request to obtain a unique identification key of the dynamic resource request; Compare the key of the dynamic resource request with the key in the database; If the key of the dynamic resource request is consistent with the key in the database, it means that the dynamic resource request has been cached in the database; If the key of the dynamic resource request is inconsistent with the key in the database, it means that the dynamic resource request is not cached in the database.
6. The webpage white screen optimization method according to claim 1, characterized in that: The step of sending the cached data in the database to the browser for page rendering and / or data rendering includes: The cached data is sent to the browser through the webview interceptor so that the browser can render the page. At the same time, the request is sent to the server through the webview interceptor to obtain the latest request information; Receive the latest request information returned by the server; Perform hash value calculation on the latest request information and the cached data in the database to obtain the hash value of the latest request information and the hash value of the cached data in the database; Compare the hash value of the latest request information with the hash value of the cached data in the database to see if they are consistent; If not, the webview interceptor is used to trigger the refresh page logic processing so that the browser can refresh and render the page; and / or The cached data in the database is returned to the browser through an interface-level cache tool so that the browser can render the data.
7. The WBE white screen optimization method according to claim 1, characterized in that: If so, before the step of sending the cached data in the database to the browser for page rendering and / or data rendering, the method further includes: Based on a preset time condition, performing a data validity check on the cached data in the database; Clear cached data that does not meet the data validity period; and / or Checking the survival time of the cached data; If the survival time of the cached data meets a preset threshold, the cached data is directly deleted.
8. The webpage white screen optimization method according to claim 1, characterized in that: If so, after the step of sending the cached data in the database to the browser for page rendering and / or data rendering, the method further includes: If not, the request is sent to the server through the webview interceptor to obtain the response data returned by the server; Receive the response data returned by the server; Performing a whitelist check on the address information in the response data returned by the server through the webview interceptor; caching the response data that passes the whitelist check, and sending the response data to the browser for the browser to render the page; and / or Cache the request through an interface-level cache tool, send the request to the server, and wait for the server to return response data; When the response data returned by the server is received, the response data is cached and sent to the browser for the browser to render the data.
9. A web page white screen optimization device, characterized in that: The webpage white screen optimization device comprises: A request interception module is used to intercept requests sent by the browser according to the type of request through a webview interceptor and / or an interface-level cache tool; A cache checking module, used to check whether the request has been cached in the cache database through a webview interceptor and / or an interface-level cache tool; The cache processing and updating module is used to send the cache data in the database to the browser for page rendering and / or data rendering.
10. A web page white screen optimization terminal device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the web page white screen optimization method according to any one of claims 1 to 8.
11. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the web page white screen optimization method according to any one of claims 1 to 8 are implemented.
12. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the web page white screen optimization method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Network information processing method and device and electronic equipment
CN110287432A
Page loading rendering optimization method and device, equipment and medium
CN116304438A
Cited By
Response result cache optimization method and device, equipment, storage medium and product
CN119583648A
Response result cache optimization method and device, equipment, storage medium and product
CN119583648B
Webpage view cache optimization method and system based on response header rewriting
CN121356898A
Terminal caching method and device for Web interface, equipment and medium
CN121388307A
Device-level intelligent rendering optimization method and system, medium and device
CN121392090A
