A method for loading a web view
Patent Information
- Application Number
- CN202611180737.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-10-23
AI Technical Summary
[0004]然而,在上述即时加载方式下,网页视图实例的创建、网络请求及页面渲染过程均在用户触发后串行执行,导致页面加载耗时较长;同时,受限于网页视图实例与创建它的页面组件运行环境强绑定的特性,现有技术难以将已加载完成的网页视图实例在不同页面组件之间安全复用,造成系统资源的重复占用及跨页面组件迁移时的功能异常风险
[0010]本公开的有益效果是:采用本公开提供的网页视图的加载方法,响应于页面打开请求,启动目标页面容器,并通过预加载池从当前应用程序的根页面容器的保活挂载节点获取预先加载的网页视图实例;将所述网页视图实例从所述保活挂载节点移除;基于所述目标页面容器对所述网页视图实例的运行环境进行更新;将所述网页视图实例添加至所述目标页面容器的视图容器中,并在所述终端设备的显示界面上渲染显示所述网页视图实例对应的页面内容。上述方式使得用户点击目标入口组件后,可以直接获取已在后台预加载完成的网页视图实例,跳过了相关技术中网页视图实例创建、网络请求和页面渲染三个阶段,实现了H5页面的秒开效果。此外,通过将网页视图实例从保活挂载节点移除并基于目标页面容器进行运行环境更新的方式,使得网页视图实例可以平滑地从后台预加载宿主迁移至前台目标页面容器,保证了复用后功能的完整性和系统资源的正确归属。采用本公开提供的方法,可以将网页视图实例添加至视图容器并渲染显示,使得用户无需等待即可看到已加载完毕的完整页面内容。
Smart Images

Figure CN122964385A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of Internet technology, and more specifically, to a method for loading a webpage view. Background Technology
[0002] In mobile terminal device applications, HyperText Markup Language 5 (H5) pages are widely used to present various dynamic business content due to their cross-platform and easy-to-update characteristics.
[0003] Currently, mobile applications typically use an on-demand loading method when loading the aforementioned web pages. That is, after receiving a user-triggered command, the application sequentially executes the creation of a web page view instance, the request for network resources, and the rendering of the page content, ultimately presenting the web page on the terminal display interface.
[0004] However, under the aforementioned instant loading method, the creation of the webpage view instance, network requests, and page rendering processes are all executed sequentially after user triggering, resulting in a long page loading time. At the same time, due to the strong binding between the webpage view instance and the runtime environment of the page component that created it, existing technologies cannot safely reuse the loaded webpage view instance between different page components, causing duplicate occupation of system resources and the risk of functional abnormalities when migrating across page components. Summary of the Invention
[0005] The embodiments disclosed herein address the shortcomings of the prior art by providing a method for loading a webpage view, enabling users to see the fully loaded page content without waiting.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this disclosure are as follows: In a first aspect, one embodiment of this disclosure provides a method for loading a webpage view, applied to a terminal device, the method comprising: In response to a page open request, the target page container is launched, and a preloaded web page view instance is obtained from the keep-alive mount node of the current application through the preload pool; Remove the webpage view instance from the keep-alive mount node; The runtime environment of the webpage view instance is updated based on the target page container; Add the webpage view instance to the target page container and display the page content corresponding to the webpage view instance.
[0007] Secondly, one embodiment of this application provides a webpage view loading device, the device comprising: an acquisition module, a removal module, an update module, and a display module, wherein: The acquisition module is used to respond to a page opening request, start the target page container, and obtain a preloaded web page view instance from the keep-alive mount node of the root page container of the current application through the preload pool. The removal module is used to remove the webpage view instance from the keep-alive mounting node; The update module is used to update the runtime environment of the webpage view instance based on the target page container; The display module is used to add the webpage view instance to the view container of the target page container, and render and display the page content corresponding to the webpage view instance on the display interface of the terminal device.
[0008] Thirdly, another embodiment of this application provides a computer device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor communicates with the memory via the bus, and the processor executes the machine-readable instructions to perform the steps of any of the methods described in the first aspect above.
[0009] Fourthly, another embodiment of this application provides a storage medium storing a computer program, which, when executed by a processor, performs the steps of any of the methods described in the first aspect above.
[0010] The beneficial effects of this disclosure are as follows: Using the webpage view loading method provided in this disclosure, in response to a page open request, a target page container is started, and a pre-loaded webpage view instance is obtained from the keep-alive mounting node of the root page container of the current application through a pre-loading pool; the webpage view instance is removed from the keep-alive mounting node; the runtime environment of the webpage view instance is updated based on the target page container; the webpage view instance is added to the view container of the target page container, and the page content corresponding to the webpage view instance is rendered and displayed on the display interface of the terminal device. This method allows users to directly obtain a webpage view instance that has already been pre-loaded in the background after clicking on the target entry component, skipping the three stages of webpage view instance creation, network request, and page rendering in related technologies, achieving a near-instantaneous opening effect for H5 pages. Furthermore, by removing the webpage view instance from the keep-alive mounting node and updating the runtime environment based on the target page container, the webpage view instance can be smoothly migrated from the background pre-loading host to the foreground target page container, ensuring the integrity of the reused functionality and the correct allocation of system resources. Using the method provided in this disclosure, web page view instances can be added to a view container and rendered, allowing users to see the fully loaded page content without waiting. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of this disclosure and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This illustration shows a schematic diagram of the architecture of a service system provided in an embodiment of the present disclosure; Figure 2 A schematic diagram of the process for updating the operating environment provided in an embodiment of this disclosure is shown; Figure 3 A flowchart illustrating a method for loading a webpage view according to another embodiment of this disclosure is shown; Figure 4 A schematic diagram of the structure of a webpage view loading device provided in an embodiment of the present disclosure is shown; Figure 5 A schematic diagram of the structure of a webpage view loading device provided in another embodiment of this disclosure is shown; Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of this disclosure is shown. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this disclosure are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this disclosure. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this disclosure illustrate operations implemented according to some embodiments of this disclosure. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical operational relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this disclosure, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0014] Furthermore, the described embodiments are merely some, not all, of the embodiments of this disclosure. The components of the embodiments of this disclosure typically described and illustrated in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the drawings is not intended to limit the scope of the claimed disclosure, but merely to illustrate selected embodiments of the disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0015] It should be noted that the term "comprising" will be used in the embodiments of this disclosure to indicate the presence of the features subsequently declared, but does not exclude the addition of other features.
[0016] This disclosure is applied to client applications on terminal devices. For dynamic business pages in the form of HyperText Markup Language 5 (H5) web pages, such as high-frequency H5 pages like dynamic activity pages, the creation of the web page view instance and the loading of page content are completed in the background before the user clicks the entry component. After the user clicks the entry component, the ready web page view instance is reused directly to achieve the effect of instant opening of H5 pages.
[0017] As an example, the method provided in this disclosure can be applied to homepage entry scenarios, such as application homepages displaying various activity entry points, such as activity entry controls. When an activity entry point is displayed on the current screen, preloading is triggered. After the user clicks the entry point, the preloaded webpage view instance is directly reused to achieve instant opening of the H5 page. Alternatively, in tab switching scenarios, where multiple tabs are switched within the application, some of which carry H5 pages (such as activity pages under the video tab), this disclosure completes preloading before the user switches to that tab, and the page is displayed immediately when the user switches. Or, in scenarios where H5 is embedded within the same page, such as switching between different modules within the same page, this disclosure achieves instant opening of H5 in scenarios with the same page container by injecting a preloaded webpage view (WebView) from the outside.
[0018] Figure 1 The diagram illustrates a flowchart of a webpage view loading method according to an embodiment of this disclosure, as shown below. Figure 1 As shown, the method includes steps 110-140, wherein: Step 110: In response to the page open request, start the target page container and obtain a preloaded web page view instance from the keep-alive mount node of the current application through the preload pool.
[0019] In some embodiments, the target page container may be launched in response to a user's triggering action on the target entry component; or, in response to a page routing event within the application, the target page container, for example, automatically executes page routing after the application completes user login.
[0020] The target entry component is a user interface (UI) element displayed on the current screen that the user can click, such as an incentive task entry card or a benefit widget. The target entry component is bound to a Uniform Resource Locator (URL) of the H5 page, and clicking the target entry component will trigger a page jump.
[0021] Triggering actions are click or touch interactions performed by the user on the target entry component.
[0022] The target page container is a UI component in an operating system used to hold and display H5 page content. In this embodiment of the disclosure, the target page container is a target UI component used to hold web page content.
[0023] The preload pool is a management component in the terminal device's memory that maintains a mapping table of web view instances, using Uniform Resource Locators (URLs) as keys, as a singleton. Each entry (PoolEntry) contains the web view instance, the original URL, the User Agent (UA) configuration, the usage status flag (isInUse), and the cached page title (cachedTitle). The preload pool is responsible for the creation, storage, querying, retrieval, and destruction of web view instances.
[0024] The root page container is the main interface page container of the current application. It has the longest lifespan in the application's lifecycle and serves as the host during the preloading phase.
[0025] A keep-alive mount node is a temporary view container within the root page container used to host webpage view instances during the preloading phase. In one embodiment of this disclosure, the keep-alive mount node can be a DecorView of the root page container, serving as a temporary parent container for the webpage view instance, enabling the webpage view instance to trigger complete rendering pipeline initialization without interfering with the user's currently visible interface. In another embodiment, the keep-alive mount node can also be a floating window view of the root page container added through a window manager. This floating window view can also provide a Window environment for the webpage view instance to trigger rendering pipeline initialization, and the floating window is transparent and focusless, without interfering with the user's currently visible interface. This disclosure does not limit the specific implementation of the keep-alive mount node.
[0026] A pre-loaded webpage view instance is a webpage view component instance that has already completed loading the page content in the background before the user triggers an action; it is in a state where it has been loaded but is not visible.
[0027] After a user performs a trigger operation on the target entry component, the application on the terminal device responds to the operation and launches the pre-configured target page container. The target page container is used to hold and display the content of the target H5 page.
[0028] At the same time as or during the startup of the target page container, the current application calls the acquire method of the preload pool, using the target Uniform Resource Locator corresponding to the target entry component as the key, to query whether there is a pre-loaded web page view instance in the preload pool.
[0029] If the query confirms the existence of the web view instance, the preload pool retrieves it from the keep-alive mount node of the root page container of the current application. Since the web view instance has already been mounted on the keep-alive mount node during the preload phase and has completed the full rendering pipeline initialization and page content loading through the keep-alive mount node, the retrieved web view instance is in a ready state after the page has been loaded and can be directly used for display on the display interface.
[0030] In this embodiment of the disclosure, before obtaining the loaded webpage view instance from the keep-alive mounting node, it is necessary to query the preloading pool for a corresponding webpage view instance entry using the target Uniform Resource Locator as the key; if it exists and the webpage view instance entry is not occupied, the webpage view instance is obtained and the webpage view instance entry is marked as occupied.
[0031] The usage status flag (isInUse) of a webpage view instance entry indicates whether the webpage view instance is currently in use. When an entry is marked as occupied, it means that the webpage view instance has been acquired and is about to / is being used in the foreground, and other concurrent requests cannot acquire the same instance.
[0032] When a user performs a trigger operation on the target entry component, and the target page container starts, the application uses the target Uniform Resource Locator (URL) as the query key to search the preload pool for a corresponding web view instance entry. If no corresponding entry exists in the preload pool, meaning the URL has not triggered preloading or preloading has not yet completed, the retrieval fails, and the application must proceed with the regular web view creation and loading process.
[0033] If a corresponding entry exists in the preload pool, the application further checks the entry's usage status flag. Each web view instance entry contains a usage status flag (isInUse) to indicate whether the web view instance is currently occupied. If the entry's usage status flag indicates "not occupied," the application retrieves the web view instance from the preload pool and updates the entry's usage status flag to "occupied," preventing other concurrent retrieval requests from obtaining the same web view instance again.
[0034] If the usage status flag of the entry indicates "occupied", it means that the web view instance is being used by other requests, such as when a user has opened the page and has not yet closed it. In this case, the application will not repeatedly obtain the same instance, but will instead perform the normal web view creation and loading process.
[0035] The aforementioned method of using Uniform Resource Locators (URIs) as keys for precise lookups ensures that each URI corresponds to only one web view instance, guaranteeing the reliability and accuracy of the retrieval operation. By using a status flag (isInUse), the problem of multiple requests simultaneously retrieving the same web view instance in concurrent scenarios is prevented, avoiding state inconsistencies and abnormal page display caused by the reuse of the same instance, thus ensuring safety in multi-threaded / concurrent scenarios.
[0036] Step 120: Remove the web view instance from the keep-alive mount node.
[0037] Since a view instance cannot exist in two parent containers simultaneously, it needs to be removed from the original parent container and then added to the new parent container. During the preloading phase, the keep-alive mount node acts as the original parent container for the webpage view instance, providing the Window environment required to trigger the rendering pipeline initialization. However, during the reuse phase, the webpage view instance needs to be moved to the view container of the target page container for foreground display; therefore, it needs to be detached (removed) from the original parent container. After the view is removed, the visibility of the webpage view instance changes from invisible to visible.
[0038] After the removal operation is completed, the webpage view instance no longer belongs to the view tree of the keep-alive mounted node, but becomes an independent view object, waiting to be added to the view container of the target page container later.
[0039] The method described above, which removes the webpage view instance from the keep-alive mount node, ensures a smooth migration of the same view instance between different page containers. Simultaneously, the visibility of the webpage view instance is switched to visible upon removal, preparing the user to see the already loaded page content.
[0040] Step 130: Update the runtime environment of the webpage view instance based on the target page container.
[0041] The runtime environment of a webpage view instance is a collection of environmental information required for the instance to run, including but not limited to: page container references, such as those affecting the correct attribution of system interactions like file selection and permission requests; and a JavaScript bridge, used for communication between JavaScript and the client. The runtime environment ensures that all functions of the webpage view instance can work correctly in the new environment.
[0042] Updating the runtime environment of a webpage view instance is the process of replacing / adapting the old runtime environment information held in the webpage view instance to the new target runtime environment information.
[0043] During the preloading phase, the webpage view instance is mounted on the keep-alive mount node of the root page container. Its internal runtime environment information, such as page container references and JS bridges, is bound to the root page container. When the webpage view instance is migrated to the target page container, this runtime environment information still points to the old root page container. If it is not updated, subsequent loading errors or memory leaks may occur. The specific content to be updated varies depending on whether the target page container and the root page container are the same page container.
[0044] Figure 2 A flowchart illustrating the process of updating the operating environment according to an embodiment of this disclosure is shown, as follows: Figure 2 As shown, step 130 may include: steps 131-133, wherein: Step 131: If the target page container is not the same page container as the root page container, update the page container reference held in the view client and / or web client of the web page view instance to the target page container.
[0045] Step 132: Unregister all registered JS bridges for the webpage view instance.
[0046] Step 133: Rebuild the full JS bridge with the target page container as the runtime environment.
[0047] In a cross-page container scenario, steps 131-133 will be executed sequentially.
[0048] In some embodiments, when the target page container and the root page container are the same page container, the runtime environment update for the web page view instance only includes rebuilding the full JS bridge with the target page container as the runtime environment.
[0049] The above steps update the runtime environment of the webpage view instance based on the target page container, ensuring that system interactions such as file selection and permission requests are correctly routed to the target page container, avoiding issues such as unresponsive interactions or incorrect attribution; unregistering the old JS bridge releases the old page container / Fragment reference, avoiding memory leaks; and rebuilding the JS bridge with the new page container as the runtime environment ensures that JavaScript and client communication callbacks are correctly triggered and routed to the target object.
[0050] In the above scenario with the same page container, since the page container reference of the webpage view instance has not changed, it is only necessary to rebuild the full JS bridge with the target page container as the runtime environment. This ensures that the communication callback between JavaScript and the client is correctly routed, while avoiding unnecessary runtime environment reset operations, preventing page flickering or white screen, and improving the smoothness of page display.
[0051] Step 140: Add the webpage view instance to the target page container and display the page content corresponding to the webpage view instance.
[0052] The target page container predefines a view container, which serves as the layout container for holding web page view instances. The application calls the view container's "Add Child View" method to add the web page view instance as a child view to the view container's view tree. After being added, the web page view instance becomes part of the view container, and its layout parameters and display area are managed by the view container.
[0053] After addition, the webpage view instance becomes visible in the foreground. Since the page content has been pre-loaded, there is no need to re-execute the loading process; instead, the already loaded page content is directly rendered onto the terminal device's display interface.
[0054] This method, which adds a pre-loaded webpage view instance to the view container of the target page and renders it on the terminal device's display interface, skips the sequential stages of WebView creation, network requests, and page rendering. From clicking the entry point to seeing the full page, users no longer need to wait for a certain loading time; instead, they only need a very short time for view addition and rendering, achieving the instant loading effect of H5 pages.
[0055] At the same time, the application sends a notification (notifyPageFirstVisible) to the front end in the web page view instance. After receiving the notification, the front end performs page display initialization operations, such as setting full-screen mode, so that the user can see the complete H5 page on the display interface.
[0056] The notification is now visible on the front-end page for the first time, allowing the front-end to perform initialization operations at the correct time. This avoids side effects such as event tracking and page animations being incorrectly triggered during the preloading phase, ensuring the correctness of the business logic. Users ultimately see a fully loaded page, providing an experience largely consistent with the native page.
[0057] The webpage view loading method provided in this disclosure responds to a page open request by starting the target page container and obtaining a pre-loaded webpage view instance from the keep-alive mount node of the root page container of the current application through a pre-loading pool. The webpage view instance is then removed from the keep-alive mount node. The runtime environment of the webpage view instance is updated based on the target page container. The webpage view instance is then added to the view container of the target page container, and the page content corresponding to the webpage view instance is rendered and displayed on the terminal device's display interface. This method allows users to directly access the pre-loaded webpage view instance after clicking the target entry component, skipping the three stages of webpage view instance creation, network request, and page rendering in related technologies, achieving instant opening of H5 pages. Furthermore, by removing the webpage view instance from the keep-alive mount node and updating the runtime environment based on the target page container, the webpage view instance can be smoothly migrated from the background pre-loading host to the foreground target page container, ensuring the integrity of the reused functionality and the correct allocation of system resources. Using the method provided in this disclosure, webpage view instances can be added to the view container and rendered, allowing users to see the fully loaded page content without waiting.
[0058] Figure 3 A flowchart illustrating a webpage view loading method according to another embodiment of this disclosure is shown, such as... Figure 3 As shown, before step 110, the method further includes steps 101-102, wherein: Step 101: In response to the display of the target entry component in the current scene, and when the current scene meets the preloading triggering conditions, determine the target Uniform Resource Locator corresponding to the target entry component, and create a web view instance for loading the target Uniform Resource Locator through the preloading pool.
[0059] The current scenario refers to the interface or runtime environment in which the user is currently in the application. The entry component displayed may differ in different scenarios.
[0060] The target Uniform Resource Locator (URL) is the URL of the H5 page that the target entry component points to; that is, the network address of the page content that needs to be loaded and displayed after the target entry component is clicked. The preloading phase involves preloading the page content for this network address.
[0061] A network view instance is a component instance used to load and render H5 page content. In this embodiment of the disclosure, each webpage view instance corresponds to a target Uniform Resource Locator (URL) for loading page content at the network address indicated by the URL.
[0062] Preloading trigger conditions are at least one condition used to determine whether preloading is allowed. These include, but are not limited to, scenario whitelist verification, remote switch status verification, Uniform Resource Locator (URI) deduplication verification, network type verification, device battery level verification, or time period distribution verification. These conditions control the timing and scope of preloading. For example, preloading trigger conditions could be: the current scenario is within a preset whitelist and the remote switch is enabled, and the target URI is not in the preloading process or is already preloaded; or, the current network type is Wi-Fi and the device battery level is above a preset battery threshold; or, the current time is during a preset off-peak period and the target URI is not in the preloading process or is already preloaded.
[0063] In some embodiments, before step 101, the method further includes: determining that the current scenario meets the preloading triggering condition when the current scenario is within a preset whitelist, the remote switch is enabled, and the target Uniform Resource Locator (URL) is neither in the preloading process nor has it been preloaded. For example, when the current scenario is an incentive task scenario, the remote switch is enabled, and the target URL has not yet started preloading, it is determined that the preloading triggering condition is met; or, when the current scenario is a welfare scenario, the remote switch is enabled, but the target URL has already been preloaded, it is determined that the preloading triggering condition is not met, and the webpage view instance is not created again.
[0064] The scenario whitelist specifies high-frequency scenarios that require preloading, such as incentive task scenarios, welfare scenarios, comic welfare tab scenarios, or activity pop-up entry scenarios. Scenarios not on the whitelist will not trigger preloading to avoid unnecessary resource consumption. The remote switch status verification is used to check whether the remote switch is enabled. The remote switch is configured and issued by the server to dynamically control the preloading function to be enabled or disabled. The preloading function can be turned off at any time when needed.
[0065] In some embodiments, the Uniform Resource Locator (URL) deduplication check is used to check whether the target URL has already been recorded in the preloading pool as being preloaded or has been preloaded completely. If a corresponding web view instance already exists in the preloading pool for the target URL, it will not be created again to avoid wasting resources.
[0066] When the preload trigger condition indicates that preloading is allowed, the application determines that the current scene meets the preload trigger condition. Subsequently, based on the target entry component displayed in the current scene, the application determines the target Uniform Resource Locator (URL) corresponding to that entry component, i.e., determines the address of the H5 page that needs to be loaded after the target entry component is clicked, and creates a web view instance for loading the URL through the preload pool.
[0067] When creating a webpage view instance, the preload pool creates and writes a corresponding entry to the pool using the target URI as the key. This entry contains information such as the webpage view instance, the target URI, and usage status flags. Each webpage view instance is specific to a particular target URI and is used to load the page content corresponding to that address; it is not reused for other URIs. Loading is only initiated through the webpage view instance after the entry has been written. This way, when the loading completion callback is triggered, the corresponding entry already exists in the preload pool, and operations such as updating the loading status can be performed normally, avoiding the problem of callbacks failing to locate the target entry because the entry has not yet been written.
[0068] Step 102: Mount the web page view instance to the keep-alive mount node of the root page container of the current application in an invisible state, and load the page content corresponding to the target Uniform Resource Locator through the web page view instance.
[0069] The preloading pool mounts and loads web view instances only when the root page container is in the foreground. If the root page container is currently in the background, mounting and loading are automatically paused and resumed only when the root page container returns to the foreground. This ensures that operations on web view instances are always performed when the page container is in the foreground, avoiding system errors or rendering problems caused by background operations on the View.
[0070] When a webpage view is in an invisible state, although the webpage view instance exists in the view tree, it will not display any content on the screen, and the user will not be aware of its existence at all. In this embodiment of the disclosure, the invisible state is also known as the hidden state (GONE).
[0071] The root page container is the main interface page container of the current application (such as the Home page container). It serves as the host for the web page view instance during the preloading phase and provides the necessary Window environment for background preloading.
[0072] In some embodiments, the visibility of a webpage view instance can be set to invisible, and it can be mounted to a keep-alive mount node at a preset size.
[0073] The preset size can be a non-zero size such as 300×300 or 100×100.
[0074] In this embodiment, to further reduce resource overhead during the preloading phase, the preset size can be set to 0×0. A 0×0 size is sufficient to trigger the Android View system to perform a complete size layout / measurement layout, ensuring that the WebViewCore inside the webpage view instance receives valid size information, allowing the JavaScript runtime environment to initialize correctly, thereby guaranteeing the correct execution of the page logic.
[0075] In the invisible state, the web page view instance does not participate in the actual drawing, avoiding unnecessary pixel rendering overhead. The 0x0 size further ensures that no pixels are rendered to the screen, making the preloading process completely imperceptible to the user. The user cannot see any interface flickering or changes, while minimizing resource overhead, thus achieving a balance between minimizing resource overhead and ensuring the integrity of the rendering pipeline.
[0076] It should be understood that the preset size of 0x0 is only used on the mounting and keep-alive mounting nodes during the preloading phase, and is used to complete the rendering pipeline initialization and page loading in the background with minimal cost. After the web page view instance is retrieved and added to the view container of the target page container, the Android View system will re-execute measure / layout according to the container constraints, automatically adjusting the web page view instance to the size of the view container, without affecting the final page layout.
[0077] In some embodiments, a query parameter can be added to the target Uniform Resource Locator (URL) to indicate the preload status.
[0078] The query parameters are used to indicate the preloading status, that is, to inform the front end that the current loading stage is the preloading stage rather than the normal access stage for the user.
[0079] When the application loads the page content corresponding to the target Uniform Resource Locator through the web view instance, it adds a query parameter to the target Uniform Resource Locator. When the front end receives the loading request with this query parameter, it can identify that the current stage is a warm-up stage, and thus pause side effects such as event tracking and page animation. The side effects will be executed again when the page is actually displayed.
[0080] To facilitate front-end recognition of the preloading state, the application adds a query parameter (e.g., preload=1) to the end of the target Uniform Resource Locator when initiating loading. Upon receiving a loading request with this query parameter, the front-end can recognize that it is currently in the preloading phase, thereby pausing the execution of side-effect operations such as event tracking and page animations, and only completing the silent loading of the page content, thus avoiding triggering unnecessary business logic before the user actually sees the page.
[0081] In this embodiment of the disclosure, the preloading process has some preset mechanisms, such as injecting a weak reference to the root page container into the preloading pool when the root page of the current application is initialized before loading the page content.
[0082] During the initial setup phase when the root page is created and launched, the application performs a series of preparatory tasks, including but not limited to loading the interface layout, initializing components, and preloading resources. In this embodiment, initialization injection is completed during the initial setup phase of the root page.
[0083] Injection is the operation of passing a weak reference to the root page container to the preload pool and making it hold that reference. After injection, the preload pool internally stores this weak reference for use in subsequent preload processes.
[0084] Weak references are a type of reference where a weak reference to the root page container is injected into the preload pool. When the root page container is garbage collected by the system, the weak reference will automatically become invalid and will not prevent the root page container from being garbage collected. This avoids memory leaks caused by the preload pool holding a strong reference to the root page container.
[0085] In this embodiment of the disclosure, after the application is launched on the terminal device, it first enters the root page (such as the homepage) of the current application. During the initialization of the root page, the application performs a series of initialization preparation tasks, including the initialization of the preload pool.
[0086] Specifically, during the initialization phase of the root page, the application obtains an instance of the root page container, encapsulates the page container instance as a weak reference, and then injects the weak reference into the preload pool by calling the initialization method of the preload pool (such as initWebViewPool(Home page container)).
[0087] When the preloading pool receives a weak reference to the root page container, it stores it internally. Because it uses a weak reference, the weak reference does not prevent the root page container from being garbage collected by the system. That is, when the root page container is destroyed due to configuration changes or system memory constraints, the weak reference automatically becomes invalid, and the preloading pool will not hold a destroyed page container instance, thus avoiding the risk of memory leaks.
[0088] Once the preloading pool obtains a weak reference to the root page container, it possesses the necessary host environment for subsequent background preloading. In the subsequent preloading process, when a webpage view instance needs to be created and mounted onto the Window to trigger the rendering pipeline initialization, if the caller provides a page container instance, that instance is used first. If the page container provided by the caller is empty, it falls back to the weak reference to the root page container held by the preloading pool during the initialization phase, attempting to obtain the root page container instance from that weak reference. If neither of these methods yields a valid page container instance—meaning the weak reference has expired or the root page container has been destroyed—the preloading process terminates to avoid operating on an invalid page container.
[0089] In addition, the preload pool performs a protective check when injecting weak references. If the root page container is already destroyed, the injection operation is terminated to prevent invalid references from being saved.
[0090] After mounting is complete, the application loads the page content corresponding to the target URI through the web view instance. When initiating loading, the loading action is delayed until after the view root node (ViewRootImpl) of the web view instance has been attached, using the web view instance's delayed post method. This ensures that the hardware-accelerated runtime environment is ready before triggering loading, avoiding loading exceptions due to an unprepared rendering pipeline. The application passes the target URI to the web view instance, calls its load method to initiate a network request, and obtains and parses the H5 page resources.
[0091] In some embodiments, in response to the destruction of a web page view instance, the corresponding entry is removed from the preload pool using the target Uniform Resource Locator as the key.
[0092] The destruction of a webpage view instance is the process of closing the webpage view instance and releasing the system resources it occupies. In this embodiment of the disclosure, when the user closes the page, the application actively calls the destruction method of the webpage view instance to reclaim memory resources.
[0093] When a user closes a page after use, such as by clicking the back or close button, the target page container is destroyed, and the web view instance contained within it also enters the destruction process. Simultaneously, the application detects the corresponding Uniform Resource Locator (URL) for that web view instance and removes the corresponding entry from the preloading pool using that URL as the key.
[0094] Specifically, when a webpage view instance is created during the preloading phase, a corresponding entry for that Uniform Resource Locator (URL) is established in the preloading pool. Even after the user closes the page and the webpage view instance is destroyed, the corresponding entry remains in the preloading pool, marked as occupied. In response to the destruction event of the webpage view instance, the application proactively removes the entry from the preloading pool using that URL as the key, releasing the storage space in the preloading pool and ensuring that the URL is no longer recorded in the preloading pool.
[0095] The method described above, which synchronously removes the corresponding entry from the preload pool when a webpage view instance is destroyed, maintains the synchronization consistency between the data in the preload pool and the actual lifecycle of the webpage view instance, avoiding memory leaks and state chaos caused by invalid entries remaining in the preload pool. Simultaneously, the removal operation clears the preload pool entry corresponding to the Uniform Resource Locator (URL), removing obstacles for subsequent reloading using that URL as the key. The preload pool no longer considers that URL to have been preloaded, thus allowing new preloading processes to be triggered normally. Destruction is cleanup, and cleanup creates conditions for reloading, ensuring that only valid and usable webpage view instances are stored in the preload pool, maintaining the health of the preload pool.
[0096] After the removal operation is completed, the binding between the Uniform Resource Locator (URL) and the preload pool is released. If the URL triggers preloading again subsequently, for example, if the user returns to the scenario where the entry component is located, there will be no corresponding entry in the preload pool. Therefore, a new webpage view instance can be created normally and a new preload process can begin.
[0097] Based on the same inventive concept, this disclosure also provides a webpage view loading device corresponding to the webpage view loading method. Since the principle of the device in this disclosure for solving the problem is similar to the webpage view loading method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0098] Figure 4 A schematic diagram of a webpage view loading device according to an embodiment of this disclosure is shown, as follows: Figure 4 As shown, the device includes: an acquisition module 210, a removal module 220, an update module 230, and a display module 240, wherein: The acquisition module 210 is used to respond to a page opening request, start the target page container, and obtain a preloaded web page view instance from the keep-alive mount node of the root page container of the current application through the preload pool. The removal module 220 is used to remove the webpage view instance from the keep-alive mounting node; The update module 230 is used to update the runtime environment of the webpage view instance based on the target page container; The display module 240 is used to add the webpage view instance to the view container of the target page container, and render and display the page content corresponding to the webpage view instance on the display interface of the terminal device.
[0099] In some embodiments, Figure 5 A schematic diagram of a webpage view loading device according to another embodiment of this disclosure is shown, such as... Figure 5 As shown, the device further includes: a creation module 250, configured to, in response to the display of the target entry component in the current scene and when the current scene meets the preloading trigger condition, determine the target Uniform Resource Locator (URL) corresponding to the target entry component, and create a webpage view instance for loading the target URL through a preloading pool; mount the webpage view instance in an invisible state to the keep-alive mounting node of the root page container of the current application, and load the page content corresponding to the target URL through the webpage view instance.
[0100] like Figure 5 As shown, the device also includes a determination module 260, which is used to determine that the current scene meets the preloading triggering conditions when the current scene is in a preset whitelist, the remote switch is enabled, and the target Uniform Resource Locator is not in a preloading or preloading state.
[0101] In some embodiments, the creation module 250 is specifically used to set the visibility of the webpage view instance to invisible and mount it to the keep-alive mounting node with a preset size.
[0102] In some embodiments, the creation module 250 is specifically used to add query parameters to the target Uniform Resource Locator, the query parameters being used to indicate a preloaded state.
[0103] In some embodiments, the update module 230 is specifically configured to, if the target page container and the root page container are not the same page container, update the page container reference held in the view client and / or web client of the web page view instance to the target page container; unregister all JS bridges registered by the web page view instance; and rebuild a full set of JS bridges with the target page container as the runtime environment.
[0104] In some embodiments, the update module 230 is specifically used to rebuild the full JS bridge with the target page container as the runtime environment if the target page container and the root page container are the same page container.
[0105] In some embodiments, the creation module 250 is specifically used to inject a weak reference to the root page container into the preload pool when the root page of the current application is initialized.
[0106] In some embodiments, the removal module 220 is specifically used to remove the corresponding entry from the preload pool in response to the destruction of the webpage view instance, using the target Uniform Resource Locator as the key.
[0107] In some embodiments, the acquisition module 210 is specifically used to query whether a corresponding webpage view instance entry exists in the preloading pool using the target Uniform Resource Locator as the key; if it exists and the webpage view instance entry is not occupied, then the webpage view instance is acquired and the webpage view instance entry is marked as occupied.
[0108] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0109] This disclosure also provides a computer device. Figure 6 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure, such as... Figure 6 The system includes: a processor 61, a memory 62, and optionally, a bus 63. The memory 62 stores machine-readable instructions executable by the processor 61. When the computer device is running, the processor 61 communicates with the memory 62 via the bus 63. When the machine-readable instructions are executed by the processor 61, the following steps are performed: In response to a page open request, the target page container is started, and a preloaded web page view instance is obtained from the keep-alive mount node of the root page container of the current application through the preload pool; Remove the webpage view instance from the keep-alive mount node; The runtime environment of the webpage view instance is updated based on the target page container; The webpage view instance is added to the view container of the target page container, and the page content corresponding to the webpage view instance is rendered and displayed on the display interface of the terminal device.
[0110] In an optional embodiment of this disclosure, prior to the step of launching the target page container in response to a page open request, the processor 61 is further configured to perform: In response to the display of the target entry component in the current scene, and when the current scene meets the preloading triggering condition, the target Uniform Resource Locator corresponding to the target entry component is determined, and a web page view instance for loading the target Uniform Resource Locator is created through the preloading pool; The webpage view instance is mounted to the keep-alive mount node of the root page container of the current application in an invisible state, and the page content corresponding to the target Uniform Resource Locator is loaded through the webpage view instance. The step of responding to a page open request and launching the target page container includes: In response to a user's triggering action on the target entry component, the target page container is launched.
[0111] In an optional embodiment of this disclosure, prior to the step of satisfying the preload triggering condition in the current scenario, processor 61 is further configured to execute: When the current scenario is within the preset whitelist, the remote switch is enabled, and the target Uniform Resource Locator is not in the preloading or has been preloaded, it is determined that the current scenario meets the preloading triggering conditions.
[0112] In an optional embodiment of this disclosure, the step of mounting the webpage view instance to the keep-alive mount node of the root page container of the current application in an invisible state includes: Set the visibility of the webpage view instance to invisible, and mount it to the keep-alive mounting node with a preset size.
[0113] In an optional embodiment of this disclosure, before the step of loading the page content corresponding to the target Uniform Resource Locator through the webpage view instance, the processor 61 is further configured to perform: Add a query parameter to the target Uniform Resource Locator (URL) to indicate the preload status.
[0114] In an optional embodiment of this disclosure, the step of updating the runtime environment of the webpage view instance based on the target page container includes: If the target page container is not the same page container as the root page container, update the page container reference held in the view client and / or web client of the web page view instance to the target page container. Unregister all registered JS bridges for the webpage view instance; Rebuild the full JS bridge using the target page container as the runtime environment.
[0115] In an optional embodiment of this disclosure, the step of updating the runtime environment of the webpage view instance based on the target page container includes: If the target page container and the root page container are the same page container, rebuild the full JS bridge using the target page container as the runtime environment.
[0116] In an optional embodiment of this disclosure, before the step of loading the page content corresponding to the target Uniform Resource Locator through the webpage view instance, the processor 61 is further configured to perform: When the root page of the current application is initialized, a weak reference to the root page container is injected into the preload pool.
[0117] In an optional embodiment of this disclosure, processor 61 is further configured to perform: In response to the destruction of the webpage view instance, the corresponding entry is removed from the preload pool using the target Uniform Resource Locator as the key.
[0118] In an optional embodiment of this disclosure, prior to the step of obtaining the loaded webpage view instance from the keep-alive mount node, processor 61 is further configured to perform: Use the target Uniform Resource Locator as the key to query whether a corresponding webpage view instance entry exists in the preload pool; If a webpage view instance entry exists and is not occupied, then the webpage view instance is obtained and the webpage view instance entry is marked as occupied.
[0119] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the following steps: In response to a page open request, the target page container is started, and a preloaded web page view instance is obtained from the keep-alive mount node of the root page container of the current application through the preload pool; Remove the webpage view instance from the keep-alive mount node; The runtime environment of the webpage view instance is updated based on the target page container; The webpage view instance is added to the view container of the target page container, and the page content corresponding to the webpage view instance is rendered and displayed on the display interface of the terminal device. The step of responding to a page open request and launching the target page container includes: In response to a user's triggering action on the target entry component, the target page container is launched.
[0120] In an optional embodiment of this disclosure, prior to the step of launching the target page container in response to a page open request, the processor is further configured to perform: In response to the display of the target entry component in the current scene, and when the current scene meets the preloading triggering condition, the target Uniform Resource Locator corresponding to the target entry component is determined, and a web page view instance for loading the target Uniform Resource Locator is created through the preloading pool; The webpage view instance is mounted to the keep-alive mount node of the root page container of the current application in an invisible state, and the page content corresponding to the target Uniform Resource Locator is loaded through the webpage view instance.
[0121] In an optional embodiment of this disclosure, prior to the step of meeting the preload triggering condition in the current scenario, the processor is further configured to execute: When the current scenario is within the preset whitelist, the remote switch is enabled, and the target Uniform Resource Locator is not in the preloading or has been preloaded, it is determined that the current scenario meets the preloading triggering conditions.
[0122] In an optional embodiment of this disclosure, the step of mounting the webpage view instance to the keep-alive mount node of the root page container of the current application in an invisible state includes: Set the visibility of the webpage view instance to invisible, and mount it to the keep-alive mounting node with a preset size.
[0123] In an optional embodiment of this disclosure, before the step of loading the page content corresponding to the target Uniform Resource Locator through the webpage view instance, the processor is further configured to perform: Add a query parameter to the target Uniform Resource Locator (URL) to indicate the preload status.
[0124] In an optional embodiment of this disclosure, the step of updating the runtime environment of the webpage view instance based on the target page container includes: If the target page container is not the same page container as the root page container, update the page container reference held in the view client and / or web client of the web page view instance to the target page container. Unregister all registered JS bridges for the webpage view instance; Rebuild the full JS bridge using the target page container as the runtime environment.
[0125] In an optional embodiment of this disclosure, the step of updating the runtime environment of the webpage view instance based on the target page container includes: If the target page container and the root page container are the same page container, rebuild the full JS bridge using the target page container as the runtime environment.
[0126] In an optional embodiment of this disclosure, before the step of loading the page content corresponding to the target Uniform Resource Locator through the webpage view instance, the processor is further configured to perform: When the root page of the current application is initialized, a weak reference to the root page container is injected into the preload pool.
[0127] In an optional embodiment of this disclosure, the processor is further configured to perform: In response to the destruction of the webpage view instance, the corresponding entry is removed from the preload pool using the target Uniform Resource Locator as the key.
[0128] In an optional embodiment of this disclosure, prior to the step of obtaining the loaded webpage view instance from the keep-alive mount node, the processor is further configured to perform: Use the target Uniform Resource Locator as the key to query whether a corresponding webpage view instance entry exists in the preload pool; If a webpage view instance entry exists and is not occupied, then the webpage view instance is obtained and the webpage view instance entry is marked as occupied.
[0129] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or modules may be electrical, mechanical, or other forms.
[0130] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0131] The above are merely specific embodiments of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A method for loading a webpage view, characterized in that, Applied to a terminal device, the method includes: In response to a page open request, the target page container is launched, and a preloaded web page view instance is obtained from the keep-alive mount node of the current application through the preload pool; Remove the webpage view instance from the keep-alive mount node; The runtime environment of the webpage view instance is updated based on the target page container; Add the webpage view instance to the target page container and display the page content corresponding to the webpage view instance.
2. The method according to claim 1, characterized in that, Before launching the target page container in response to a page open request, the method further includes: In response to the display of the target entry component in the current scene, and when the current scene meets the preloading triggering condition, the target Uniform Resource Locator corresponding to the target entry component is determined, and a web page view instance for loading the target Uniform Resource Locator is created through the preloading pool; The webpage view instance is mounted to the keep-alive mount node of the root page container of the current application in an invisible state, and the page content corresponding to the target Uniform Resource Locator is loaded through the webpage view instance. The step of responding to a page open request and launching the target page container includes: In response to a user's triggering action on the target entry component, the target page container is launched.
3. The method according to claim 2, characterized in that, Before the preloading trigger condition is met in the current scenario, the method further includes: When the current scenario is within the preset whitelist, the remote switch is enabled, and the target Uniform Resource Locator is not in the preloading or has been preloaded, it is determined that the current scenario meets the preloading triggering conditions.
4. The method according to claim 2, characterized in that, The step of mounting the webpage view instance to the root page container of the current application in an invisible state includes: Set the visibility of the webpage view instance to invisible, and mount it to the keep-alive mounting node with a preset size.
5. The method according to claim 2, characterized in that, Before loading the page content corresponding to the target Uniform Resource Locator through the webpage view instance, the method further includes: Add a query parameter to the target Uniform Resource Locator (URL) to indicate the preload status.
6. The method according to claim 2, characterized in that, The step of updating the runtime environment of the webpage view instance based on the target page container includes: If the target page container is not the same container as the root page container, update the page container reference held in the view client and / or web client of the web page view instance to the target page container. Unregister all registered JS bridges for the webpage view instance; Rebuild the full JS bridge using the target page container as the runtime environment.
7. The method according to claim 2, characterized in that, The step of updating the runtime environment of the webpage view instance based on the target page container includes: If the target page container and the root page container are the same page container, rebuild the full JS bridge using the target page container as the runtime environment.
8. The method according to claim 2, characterized in that, Before loading the page content corresponding to the target Uniform Resource Locator through the webpage view instance, the method further includes: When the root page of the current application is initialized, a weak reference to the root page container is injected into the preload pool.
9. The method according to claim 2, characterized in that, The method further includes: In response to the destruction of the webpage view instance, the corresponding entry is removed from the preload pool using the target Uniform Resource Locator as the key.
10. The method according to claim 2, characterized in that, Before obtaining the loaded webpage view instance from the keep-alive mounting node, the method further includes: Use the target Uniform Resource Locator as the key to query whether a corresponding webpage view instance entry exists in the preload pool; If a webpage view instance entry exists and is not occupied, then the webpage view instance is obtained and the webpage view instance entry is marked as occupied.