H5 page loading optimization method based on iOS system
By creating a cache pool in iOS system and using offline package technology and WKURLSchemeHandler request interception technology for local cache, the problem of slow loading speed when WKWebView loading H5 pages is solved, improving the user experience.
Patent Information
- Application Number
- CN202411233189.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-04
- Publication Date
- 2024-12-27
AI Technical Summary
In iOS8 and later versions, WKWebView loads the H5 page due to poor startup of WebView and network, resulting in a long loading process that affects the user experience.
By creating a cache pool for WKWebView, using offline package technology to package static resources to local storage, and using WKURLSchemeHandler request interception technology and local cache technology to optimize the H5 page loading process.
It significantly optimizes the browser kernel startup time and static resource reading speed, speed up the H5 page loading speed, and improves the user experience.
Smart Images

Figure CN119201268A_ABST
Abstract
Description
Technical Field
[0001] The invention discloses an H5 page loading optimization method based on an iOS system, and relates to the technical field of data loading. Background Art
[0002] Currently, mobile applications are developed with Hybrid technology, and H5 is the most common way to implement Hybrid technology. It not only enjoys the capabilities of Native, but also has the characteristics of low cost, high efficiency and cross-platform. However, in current projects, a large number of native apps are embedded with H5 pages, and many functions need to be implemented with H5. Starting from iOS8, WKWebView is generally used to load H5 pages in actual development. When WKWebView loads an H5 page for the first time, it is limited by the startup of WebView and poor network, so the loading process of H5 may be relatively long, and the user experience is not very ideal. Summary of the invention
[0003] In view of the problems of the prior art, the present invention provides an H5 page loading optimization method based on the iOS system, which has the characteristics of strong versatility and simple implementation, and has broad application prospects.
[0004] The specific scheme proposed by the present invention is:
[0005] The present invention provides an H5 page loading optimization method based on iOS system, comprising:
[0006] Step 1: Create a cache pool for WKWebView, create a WKWebView and add it to the cache pool. When the application starts, get the WKWebView from the cache pool to load the H5 page.
[0007] Step 2: Use offline package technology to package the static resources that WKWebView needs to load into local storage. When loading the H5 page, use WKURLSchemeHandler request interception technology to match the intercepted static resource links through the proxy method startURLSchemeTask, and read the packaged static resources in the local storage according to the match.
[0008] Step 3: Locally cache the content loaded by WKWebView in the data request to speed up the loading of H5 pages.
[0009] Furthermore, in step 1 of the H5 page loading optimization method based on the iOS system, a singleton cache pool ZWWebViewCache of WKWebView is created, the number in the cache pool is set by default, and the prepareWithCount method is called to create WKWebView and add it to the cache pool.
[0010] Furthermore, in step 2 of the H5 page loading optimization method based on the iOS system, the WKWebView Configuration method is used to register an instance object for intercepting static resource links using the WKURLSchemeHandler request interception technology.
[0011] Furthermore, in step 3 of the H5 page loading optimization method based on the iOS system, a cache expiration time and a cache capacity are set for the content to be cached locally.
[0012] The present invention also provides an H5 page loading optimization device based on iOS system, including a cache pool management module, a loading module, a static resource management module and a local cache management module.
[0013] The cache pool management module creates a cache pool for WKWebView, creates a WKWebView and adds it to the cache pool. When the application starts, the loading module obtains the WKWebView from the cache pool to load the H5 page.
[0014] The static resource management module uses offline package technology to package the static resources that WKWebView needs to load into local storage. When the loading module loads the H5 page, it uses WKURLSchemeHandler request interception technology to match the intercepted static resource links through the proxy method startURLSchemeTask, and reads the packaged static resources in the local storage according to the match.
[0015] The local cache management module locally caches the content loaded by WKWebView in the data request to speed up the loading of H5 pages.
[0016] Furthermore, the cache pool management module of the H5 page loading optimization device based on the iOS system creates a singleton cache pool ZWWebViewCache of WKWebView, sets the number in the cache pool by default, and calls the prepareWithCount method to create WKWebView and add it to the cache pool.
[0017] Furthermore, the loading module of the H5 page loading optimization device based on the iOS system uses the WKWebView Configuration method to register the instance object, which is used to intercept static resource links using the WKURLSchemeHandler request interception technology.
[0018] Furthermore, the local cache management module of the H5 page loading optimization device based on the iOS system sets the cache expiration time and cache capacity for the content to be locally cached.
[0019] The benefits of the present invention are:
[0020] The present invention creates a cache pool of WKWebView, obtains WKWebView from the cache pool to load H5 pages when the application starts, optimizes the browser kernel startup time, uses offline package technology to package static resources that WKWebView needs to load into local storage, speeds up the reading speed of static resources, locally caches the content loaded by WKWebView in data requests, and speeds up the loading of H5 pages. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a schematic flow chart of the method of the present invention. DETAILED DESCRIPTION
[0022] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0023] Example 1
[0024] The present invention provides an H5 page loading optimization method based on iOS system, comprising:
[0025] Step 1: Create a cache pool for WKWebView, create WKWebView and add it to the cache pool. When the application starts, get WKWebView from the cache pool to load the H5 page.
[0026] You can further create a singleton cache pool ZWWebViewCache for WKWebView, set the number of cache pools by default, and call the prepareWithCount method to create WKWebView and add it to the cache pool.
[0027] Create a cache pool and get WKWebView from the cache pool to load the H5 page when the App starts. This optimizes the browser kernel startup time and speeds up the loading of the H5 page.
[0028] Step 2: Use offline package technology to package the static resources that WKWebView needs to load into local storage. When loading the H5 page, use WKURLSchemeHandler request interception technology to match the intercepted static resource links through the proxy method startURLSchemeTask, and read the packaged static resources in local storage according to the match. The WKWebView Configuration method setURLSchemeHandler(_:forURLScheme:) is used to register the instance object, which is used to intercept the static resource link using the WKURLSchemeHandler request interception technology. The page link of the static resource is based on the custom user protocol scheme.
[0029] Among them, WKWebView loads static resources such as CSS, JS, etc., which will affect the loading speed. The present invention uses offline package technology to package relatively large static resources into a local copy, obtains static resource links for matching through WKURLSchemeHandler request interception technology, and directly reads the packaged static resources in the local storage according to the match, thereby speeding up the loading speed of H5 pages.
[0030] Step 3: Locally cache the content loaded by WKWebView in the data request to speed up the loading of H5 pages.
[0031] In step 3, you can set the cache expiration time and cache capacity for the locally cached content.
[0032] Example 2
[0033] The present invention also provides an H5 page loading optimization device based on iOS system, including a cache pool management module, a loading module, a static resource management module and a local cache management module.
[0034] The cache pool management module creates a cache pool for WKWebView, creates a WKWebView and adds it to the cache pool. When the application starts, the loading module obtains the WKWebView from the cache pool to load the H5 page.
[0035] The static resource management module uses offline package technology to package the static resources that WKWebView needs to load into local storage. When the loading module loads the H5 page, it uses WKURLSchemeHandler request interception technology to match the intercepted static resource links through the proxy method startURLSchemeTask, and reads the packaged static resources in the local storage according to the match.
[0036] The local cache management module locally caches the content loaded by WKWebView in the data request to speed up the loading of H5 pages.
[0037] As the information interaction and execution process between the modules of the above-mentioned device are based on the same concept as the embodiment of the method of the present invention, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.
[0038] Similarly, the device of the present invention creates a cache pool for WKWebView, obtains WKWebView from the cache pool to load the H5 page when the application starts, optimizes the browser kernel startup time, uses offline package technology to package the static resources that WKWebView needs to load into local storage, speeds up the reading speed of static resources, locally caches the content loaded by WKWebView in the data request, and speeds up the loading of the H5 page.
[0039] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.
[0040] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.
Claims
1. A method for optimizing H5 page loading based on iOS system, characterized by: include: Step 1: Create a cache pool for WKWebView, create a WKWebView and add it to the cache pool. When the application starts, get the WKWebView from the cache pool to load the H5 page. Step 2: Use offline package technology to package the static resources that WKWebView needs to load into local storage. When loading the H5 page, use WKURLSchemeHandler request interception technology to match the intercepted static resource links through the proxy method startURLSchemeTask, and read the packaged static resources in the local storage according to the match. Step 3: Locally cache the content loaded by WKWebView in the data request to speed up the loading of H5 pages.
2. According to the H5 page loading optimization method based on iOS system according to claim 1, it is characterized by In step 1, create a singleton cache pool ZWWebViewCache for WKWebView, set the number of cache pools by default, and call the prepareWithCount method to create WKWebView and add it to the cache pool.
3. According to the H5 page loading optimization method based on iOS system according to claim 1, it is characterized by In step 2, use the WKWebView Configuration method to register an instance object to intercept static resource links using the WKURLSchemeHandler request interception technology.
4. According to the H5 page loading optimization method based on iOS system according to claim 1, it is characterized by In step 3, set the cache expiration time and cache capacity for the content to be cached locally.
5. An H5 page loading optimization device based on iOS system, characterized by: Including cache pool management module, loading module, static resource management module and local cache management module, The cache pool management module creates a cache pool for WKWebView, creates a WKWebView and adds it to the cache pool. When the application starts, the loading module obtains the WKWebView from the cache pool to load the H5 page. The static resource management module uses offline package technology to package the static resources that WKWebView needs to load into local storage. When the loading module loads the H5 page, it uses WKURLSchemeHandler request interception technology to match the intercepted static resource links through the proxy method startURLSchemeTask, and reads the packaged static resources in the local storage according to the match. The local cache management module locally caches the content loaded by WKWebView in the data request to speed up the loading of H5 pages.
6. The H5 page loading optimization device based on iOS system according to claim 5 is characterized in that The cache pool management module creates a singleton cache pool ZWWebViewCache for WKWebView, sets the number of cache pools by default, and calls the prepareWithCount method to create a WKWebView and add it to the cache pool.
7. The H5 page loading optimization device based on iOS system according to claim 5 is characterized in that The loading module uses the WKWebView Configuration method to register the instance object, which is used to intercept static resource links using the WKURLSchemeHandler request interception technology.
8. The H5 page loading optimization device based on iOS system according to claim 5 is characterized in that The local cache management module sets the cache expiration time and cache capacity for the content to be cached locally.
