Webpage resource preloading and caching method and device and electronic equipment
By decompressing offline packages and creating webview instance pools when the client is first started, combined with cache configuration file management resources, the problem of slow web page loading speed is solved, fast loading and reducing network requests are achieved, and user experience is improved.
Patent Information
- Application Number
- CN202510303133.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-07-04
AI Technical Summary
In the prior art, web pages are loading slowly, user experience is poor, and web page resource preloading and cache strategies need to be optimized.
Decompress the pre-installed offline package to the local cache directory when the client is first started, create a webview instance pool, and manage resources through cache configuration files to reduce duplicate network requests.
Significantly speed up page loading, reduce the number of network requests, and improve user experience.
Smart Images

Figure CN120256757A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of web development, and particularly relates to a method, device and electronic device for preloading and caching web resources. Background Art
[0002] In the digital age, the web page loading speed is directly related to the user experience and the overall performance of the website. Among them, the web page preloading technology is a method of reducing the user waiting time by downloading the resources required for the web page in advance. Its core idea is that before the user actually requests the resources, the browser or application has already pre-obtained these resources, thus achieving a faster page loading speed. The caching technology is a method of storing resources locally or on the server side to reduce repeated network requests. Through caching, the browser or application can access the resources that have been obtained before more quickly.
[0003] In modern web development, both preloading and caching technologies are widely applied in various application scenarios; among them, web resource preloading and caching are important means to improve the web page loading speed and user experience. Currently, the strategies for web resource preloading and caching can be further optimized to ensure that the technical means of web resource preloading and caching play a greater role in modern web development. Summary of the Invention
[0004] The present invention provides a method, device and electronic device for preloading and caching web resources to solve the above technical problems in the prior art.
[0005] According to a first aspect of the present invention, there is provided a method for preloading and caching web resources, including:
[0006] Unzip a preset offline package to a local cache directory when the client is started for the first time;
[0007] Request to download a cache configuration file when the client is started, where a resource file at a specified URL is downloaded to the local cache directory, and the md5 value of the downloaded resource is written to the local cache;
[0008] Create a webview instance pool, where multiple webview instances are created for repeated use when the client is started.
[0009] Preferably, when unzipping the preset offline package to the local cache directory when the client is started for the first time, the preset offline package includes a zip package, the zip package is stored in the client's own directory, the zip package contains static resources that need to be preloaded, and when the preloaded static resources are updated, the updated static resource URL and the md5 value corresponding to the resource are written to the cache configuration file.
[0010] Preferably, when the client is started for the first time, the preset offline package is decompressed into the local cache directory, and the preset offline package is deleted after decompression.
[0011] Preferably, a cache generation mechanism is provided in the method for preloading and caching web page resources, and the cache generation mechanism includes at least one of the following operations: preset offline package, downloaded resources, written to the local cache directory, updated cache index, and cleared cache.
[0012] Preferably, a cache update mechanism is provided in the method for preloading and caching web page resources. The cache update timing is when the client is started and the webview is created; the cache update mechanism includes: a cache configuration file update mechanism.
[0013] In the cache configuration file update mechanism, when the client is opened again, a request is sent to the network to check whether the configuration file has been updated. If a 304 response is received, it means the configuration file has not been updated. If a 200 response is received, it means the configuration file has been updated, and the configuration file is downloaded to the local. Among them, the md5 value of the content of the downloaded configuration file is compared with the md5 value of the local cache to determine whether the static resources have been updated.
[0014] Preferably, the method for preloading and caching web page resources further includes:
[0015] When accessing a web page, the SDK retrieves the webview and requests the cache configuration file; determines whether the cache needs to be updated, and at the same time intercepts the network resource requests initiated by the web page. If the cache is hit, the resources are obtained from the cache, otherwise the resources are obtained through the network.
[0016] Preferably, the interception of the network resource requests initiated by the web page includes:
[0017] Determine whether the resource exists in the local cache configuration file. If it does not exist, end the resource interception; if it exists, then determine whether the md5 value corresponding to the resource is cached locally. If it is, perform resource interception; if not, end the resource interception;
[0018] Read the cached resources. If the reading is successful, return the resources. If the reading fails, download the resources through the network.
[0019] According to the second aspect of the present invention, there is provided a device for preloading and caching web page resources, including:
[0020] A decompression module, configured to decompress the preset offline package into the local cache directory when the client is started for the first time;
[0021] A request module, configured to request to download the cache configuration file when the client is started. Among them, the resource file of the specified URL is downloaded to the local cache directory, and the md5 value of the downloaded resources is written to the local cache; and
[0022] A creation module is used to create a pool of webview instances. Among them, multiple webview instances are created for reuse when the client starts.
[0023] According to the third aspect of the present invention, there is provided an electronic device, including the following steps:
[0024] A memory; and
[0025] A processor;
[0026] Wherein, the memory is used to store one or more computer instructions; the one or more computer instructions are executed by the processor to implement the method described in any one of the above.
[0027] According to the fourth aspect of the present invention, there is provided a readable storage medium, on which computer instructions are stored; wherein, when the computer instructions are executed by a processor, the method described in any one of the above is implemented.
[0028] The technical solution of the present invention can significantly accelerate the page loading speed and response time by preloading resources in advance and reducing repeated network requests; it has significant beneficial effects in improving the web page loading speed and user experience.
[0029] In terms of improving the loading speed, by preloading and caching web page resources, users do not need to wait for the download of resources when accessing the web page, thus significantly improving the loading speed.
[0030] In terms of reducing network requests, the caching mechanism can reduce the number of requests to the server, reduce the network burden, and also help save the user's network traffic.
[0031] In terms of enhancing the user experience, fast page loading and smooth user interaction can significantly improve user satisfaction and loyalty. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 is a schematic flow chart of a method for preloading and caching web page resources in an embodiment;
[0033] Figure 2 is another schematic flow chart of a method for preloading and caching web page resources in an embodiment;
[0034] Figure 3 is a schematic flow chart of intercepting network resource requests initiated by a web page in an embodiment;
[0035] Figure 4 is a schematic structural diagram of a device for preloading and caching web page resources in an embodiment;
[0036] Figure 5 It is another structural schematic diagram of a device for preloading and caching web resources in an embodiment. Specific implementation manners
[0037] It should be noted that, without conflict, the embodiments in the present invention and the features in the embodiments may be combined with each other. The present invention will be described in detail below with reference to the drawings and in combination with the embodiments.
[0038] In order to enable those skilled in the art of the present technology to better understand the solution of the present invention, the technical solution in an embodiment will be clearly and completely described below with reference to the drawings in an embodiment. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without making creative efforts shall fall within the protection scope of the present invention.
[0039] It should be noted that the terms "first", "second", etc. in the present invention are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so as to describe the embodiments of the present invention here. In addition, the terms "including the following steps" and "having", and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0040] It should be understood that when an element (such as a layer, film, region, or substrate) is described as "on" another element, the element can be directly on the other element, or there may also be an intermediate element. Moreover, in the present invention, when it is described that an element is "connected" to another element, the element can be "directly connected" to the other element, or "connected" to the other element through a third element.
[0041] Embodiment 1
[0042] Please refer to Figures 1-3 , this embodiment provides a method for preloading and caching web resources, including the following steps:
[0043] S1. When the client is started for the first time, decompress the preset offline package to the local cache directory; this step ensures that when the user uses the client for the first time, they can quickly access the preset web resources without waiting for the download of the resources;
[0044] S2. When the client starts, it requests to download the cache configuration file. Specifically, it downloads the resource file at the specified URL to the local cache directory and writes the md5 value of the successfully downloaded resource to the local cache. The advantage of this step is that when the user accesses these resources later, they can directly read from the local cache without downloading from the server again. In addition, the verification of the md5 value also ensures the integrity and consistency of the resources.
[0045] S3. Create a webview instance pool. Specifically, when the client starts, multiple webview instances are created for repeated use, which can reduce the time-consuming of creating webviews.
[0046] In one embodiment, in step S1, the preloaded offline package consists of zip packages stored in the client's own directory. The zip packages contain static resources that need to be preloaded. When the preloaded static resources are updated, the updated static resource URL and the md5 value corresponding to the resource are written to the cache configuration file.
[0047] In one embodiment, in step S1, after decompressing the preloaded offline package, the preloaded offline package can be deleted.
[0048] In one embodiment, in the step of downloading the cache configuration file in step S2, there is an example. When the client starts, it will start a thread to request the app - config.json file (i.e., the cache configuration file), and start multiple threads to process the resource download task queue. It downloads the resource file at the specified URL to the local cache directory and writes the md5 value of the successfully downloaded resource to the local cache.
[0049] In one embodiment, in step S3, when the client starts, it will create 4 webview instances by default, and the SDK can configure the number of created instances.
[0050] As Figure 2 shown in one embodiment, the method for preloading and caching web resources further includes the following steps:
[0051] S4. When accessing a web page, the SDK retrieves a webview and requests the cache configuration file; it determines whether the cache needs to be updated, and at the same time intercepts the network resource requests initiated by the web page. If the cache is hit, it obtains the resources from the cache; otherwise, it obtains the resources through the network. This step S4 belongs to the running stage.
[0052] Among them, as Figure 3 shown, the interception of the network resource requests initiated by the web page includes the following steps:
[0053] S411. Determine whether the resource is in the local cache configuration file. If not, end resource interception; if it exists, then further determine whether the md5 value corresponding to the resource is cached locally. If there is a cache, perform resource interception; if not, end resource interception.
[0054] S412. Read the cached resource. If the read is successful, return the resource. If the read fails, download the resource through the network and automatically write it to the cache.
[0055] In one embodiment, the method for preloading and caching web resources is provided with a cache generation mechanism, and the cache generation mechanism includes at least one of the following operations: presetting an offline package, downloading resources, writing to the local cache directory, updating the cache index, and cleaning the cache.
[0056] In one embodiment, the method for preloading and caching web resources is provided with a cache update mechanism, and the cache update mechanism includes: a cache configuration file update mechanism; wherein, in the cache configuration file update mechanism, when the client is opened again, a request is sent to the network to check whether the configuration file has been updated. If a 304 response is received, it means the configuration file has not been updated. If a 200 response is received, it means the configuration file has been updated, and the configuration file is downloaded to the local. Among them, the md5 value of the content of the downloaded configuration file is compared with the md5 value cached locally to determine whether the static resources have been updated.
[0057] In one embodiment, the cache update timing of the cache update mechanism is when the client starts and when the webview is created. Correspondingly, the cache update mechanism is provided with a cache cleaning timing. Specifically, currently, only passive cleaning is designed in the design scheme, and when the storage capacity reaches a limit, it is cleaned according to the usage frequency.
[0058] Term annotation:
[0059] Cache directory: The client cache directory is preferentially obtained as: / sdcard / Android / data / `applicationpackage` / cache directory; if the sd card does not exist, then / data / data / `package` / cache is obtained as the storage directory for disk caching.
[0060] Cache configuration file: app-config.json.
[0061] Offline package: The preset offline package is dist.zip.
[0062] The method for preloading and caching web resources of the present invention has a general design scheme: preloading resources + presetting offline packages + webview instance pools. The key points involved are as follows: among the preloaded static resources, the static resources that need to be cached are written into a cache configuration file, and the client downloads the resources in the configuration file and writes them into the cache directory; in the preset offline packages, static resource files with a relatively low update frequency and being commonly used can be packaged and distributed to the client, and the client directly extracts them to the local cache directory, eliminating the need to request the server to download resources for the first time; in the webview instance pools, multiple webview instances are created and reused during the client startup phase, instead of creating objects every time a web page is opened, reducing the time-consuming for creating webviews.
[0063] Embodiment 2
[0064] Please refer to Figures 1-3 , this embodiment provides a method for preloading and caching web resources, which will be elaborated from the perspective of R & D or technical implementation for easy reading and understanding; and it will be demonstrated with the help of attached drawings in order to elaborate the technical solution of the present invention clearly and completely, and highlight the inventive points and important links of the technical solution of the present invention.
[0065] The general design scheme of the method for preloading and caching web resources of the present invention is: preloading resources + presetting offline packages + webview instance pools.
[0066] The cache implementation process includes the client startup phase and the running phase. The client startup phase has the following steps:
[0067] Extract the offline package. Among them, when the client is started for the first time, the preset offline package will be extracted, and then the preset offline package will be deleted.
[0068] Download the cache configuration file. Among them, when the client starts, it will open a thread to request the app-config.json file, and start multiple threads to process the resource download task queue, download the resource file of the specified URL to the local cache directory, and write the md5 value of the successfully downloaded resource to the local cache.
[0069] Create a webview instance pool. Among them, when the client starts, 4 webview instances will be created by default, and the SDK can configure the number of created instances.
[0070] During the client running phase, when accessing a web page, the SDK will take out the first webview from the webview instance queue for use, and request the app-config.json file to determine whether the cache needs to be updated. At the same time, it intercepts the network resource requests initiated by the web page. If the cache is hit, the resource is directly obtained from the cache; otherwise, the resource is obtained through the network.
[0071] It involves a cache generation mechanism, which includes tasks such as presetting offline packages and downloading resources, writing to the local cache directory, updating the cache index, and cleaning the cache. The cache generation mechanism has the following steps:
[0072] In the preset offline package, unzip the preset package dist.zip to the local cache directory, and then delete dist.zip.
[0073] In the task queue of resource downloading, by default, up to 4 download threads are started to process this queue (up to 10 can be expanded), and the resources are downloaded to the local cache directory. The md5 of the successfully downloaded resources is written to the local cache.
[0074] In cleaning the cache, when the storage capacity reaches a limit value (configurable), the cache is cleaned according to the usage frequency.
[0075] Among them: The static resources in app-config.json ensure that except for html files, they are incrementally updated (with hash added). Otherwise, if the resource download fails, the old resources will be loaded, resulting in errors.
[0076] It involves a cache update mechanism. The cache update timing: when the client starts and when the webview is created.
[0077] In the cache configuration file (app-config.json), when the client starts for the first time, the configuration file is obtained through the network and saved locally for future use (including the file content and response headers); when the client is opened again, the network is checked to see if the configuration file has been updated. If a 304 response is received, it means the configuration file has not been updated. If a 200 response is received, the received file content is compared with the local version to determine if there is an update. If there is an update, the resource download and caching process starts.
[0078] In the cache cleaning timing of the cache update mechanism, the current design only has passive cleaning (when the storage capacity reaches a limit value, it is cleaned according to the usage frequency).
[0079] It involves an interception mechanism. When the webview requests a network resource, it uses the resource interception method provided by the webview itself. Among them, first, it is judged whether the resource exists in the local app-config.json configuration. If it does not exist, the resource interception ends. If it exists, then it is judged whether the md5 value corresponding to the resource is cached locally. If it is, the resource interception is carried out. If not, the resource interception ends; the cached resource is read. If the reading is successful, the resource is returned. If it fails, the resource is downloaded online and automatically written to the cache.
[0080] It involves a preset offline package. There are the following examples:
[0081] Host configuration preset package directory (assets):
[0082]
[0083] Meanings of each file:
[0084] ydlm: Name of the zip package (each project agrees with its respective client and configures it during sdk initialization).
[0085] config.json: Similar to app-config.json, generates an md5 cache based on the resource list in config.json and the resources in dist.zip.
[0086] dist.zip: Pre-built offline package, the dist directory generated after project construction is packaged into a zip package and unzipped to the local cache directory when the application starts.
[0087] md5: Md5 of the dist.zip file, which can be used to verify the integrity of the dist.zip package.
[0088] Among them, config.json is the same as app-config.json when the same version is launched online. It is only used to unzip the zip package to the local cache directory and write the md5 to the local cache. Other resource updates and matches are based on the online app-config.json.
[0089] Among them, the cache configuration file (app-config.json) is involved. app-config.json: List of static resources that need to be added to the offline cache policy in the project, stored in the root directory of the server.
[0090]
[0091]
[0092] lastModified: Time point of the last webpack build, which is convenient for checking whether the release is successful online.
[0093] charset: Encoding format of project resources.
[0094] orderHtml: Sorting of html files, in array format.
[0095] outputDir: Directory generated by project build.
[0096] zipDir: Name of the generated zip package.
[0097] resources: List of resources to be cached (js / css / img).
[0098] url: If it is a `CDN resource`, it is the full path; if it is not a CDN resource, it is the relative path.
[0099] md5: The md5 value of the resource corresponding to the url, which is used for client cache storage and comparison.
[0100] routers: List of html resources to be cached
[0101] url: Relative path of the html file.
[0102] content: Content of the cached html file; if it is empty, download and cache it from the online source.
[0103] regx: Regular expression to match the corresponding html file, to avoid repeated downloading of the same html file in the history routing mode.
[0104] md5: The md5 value generated from the content of the html file, which is used for client cache storage and comparison.
[0105] Among them, the priority for the client to load the resource list is: routers > resources.
[0106] Naming of the zip package: Each project agrees with its respective client and configures it during the sdk initialization. For example: The Ace Mobile Alliance is ydlm.zip, and the Planet can be xq.zip.
[0107] CDN resource file: The url field writes the full path, and the client determines whether it is a CDN resource based on whether the url contains 'http:' or 'https:'.
[0108] Among them, it involves how to generate app-config.json and the offline package.
[0109] Generating app-config.json:
[0110] const path = require('path')
[0111] const fs = require('fs')
[0112] const glob = require('glob')
[0113] const md5File = require('md5-file')
[0114] const utils = require('. / util')
[0115] const buildZip = require('. / build-zip')
[0116] const env = require('minimist')(process.argv.slice(2), {
[0117] string: ['env'],
[0118] }).env || 'ga'
[0119] / / Static resource list file name
[0120] const filename = 'app-config.json'
[0121] / / routers resources include html information
[0122] const routers = []
[0123] / / Assembled resource list
[0124] let resources = []
[0125] / / This regular expression assumes that the URL of the resource does not contain spaces
[0126] const resReg = / <(?:link|script)\s+[^>]*?(?:src|href)=['"]?([^'"\s>]+)['"]?(?:\s|>) / g
[0127] const regx = / \ / ?[^\ / ]+\.html$ / g
[0128] const regP = / \ / [^\ / ]+\.html$ /
[0129] const regH = / ^(https:|http:) /
[0130] / / Read `appConfig.json`
[0131] const appConfigSrcPath = path.join(__dirname, filename)
[0132] if (!fs.existsSync(appConfigSrcPath)) {
[0133] console.error('Please add the app-config.json file under the _build directory')
[0134] return false
[0135] }
[0136] const appConfig = JSON.parse(fs.readFileSync(appConfigSrcPath, 'utf8'))
[0137] const orderHtml = appConfig.orderHtml
[0138] const isHistory = appConfig.routerMode === 'history'
[0139] / / The dist directory for packaging can be modified for different projects
[0140] const outputDir = path.join(__dirname, '..', appConfig.outputDir)
[0141] const appConfigDistPath = path.join(outputDir, filename)
[0142] / / Currently only for the case of one cdnUrl
[0143] let cdnUrl = utils.getType(appConfig.cdnUrls) === 'array'? appConfig.cdnUrls[0] : ''
[0144] if (cdnUrl &&!regH.test(cdnUrl)) {
[0145] console.error('Each item of cdnUrls must contain https: or http:')
[0146] return false
[0147] }
[0148] cdnUrl = cdnUrl? cdnUrl.replace(regH, '') : ''
[0149] const cdnIndex = cdnUrl? 0 : -1
[0150] / / Sorted htmls list
[0151] const htmls = utils.getOrderHtmls(glob.sync(path.join(outputDir, '** / *.html')), orderHtml)
[0152] / / Get static resources in the static file directory
[0153] const staticDir = glob.sync(path.join(outputDir, '** / static / '))
[0154] / **
[0155]
[0156]
[0157] Example 3
[0158] Please refer to Figure 4 、 5 , this example provides a device for preloading and caching web page resources in the following form:
[0159] 1. Decompression module
[0160] The decompression module 10 is used to decompress the preset offline package to the local cache directory when the client is started for the first time;
[0161] 2. Request module
[0162] The request module 20 is used to request and download the cache configuration file when the client is started. Among them, the resource file of the specified URL is downloaded to the local cache directory, and the md5 value of the successfully downloaded resource is written to the local cache;
[0163] 3. Creation module
[0164] The creation module 30 is used to create a webview instance pool. Among them, multiple webview instances are created for repeated use when the client is started.
[0165] Such as Figure 5In one of the illustrated embodiments, the device for preloading and caching web resources further includes a resource acquisition module 40; when accessing a web page, the resource acquisition module 40 causes the SDK to retrieve the webview and request a cache configuration file; determines whether the cache needs to be updated, and at the same time intercepts network resource requests initiated by the web page. If the cache is hit, the resource is obtained from the cache; otherwise, the resource is obtained through the network.
[0166] It should be noted that the above device is used to implement the methods in the above embodiments, and each module in the device corresponds to each step in the method.
[0167] Embodiment Four
[0168] Based on the same inventive concept, an embodiment of the present invention provides an electronic device, including the following steps: a memory and a processor; wherein, the memory is used to store one or more computer instructions; the one or more computer instructions are executed by the processor to perform the method of any one of the above embodiments.
[0169] Embodiment Five
[0170] Based on the same inventive concept, an embodiment of the present invention provides a readable storage medium, on which computer instructions are stored; wherein, when the computer instructions are executed by the processor, the method of any one of the above embodiments is implemented.
[0171] Among them, the above one or more computer instructions can form a program.
[0172] The above program can run in the processor, or can also be stored in the memory (or referred to as a computer-readable medium). The computer-readable medium includes the following steps: permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include the following steps, but are not limited to phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include the following steps: transitory computer-readable media, such as modulated data signals and carrier waves.
[0173] These computer programs can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, thereby providing instructions executed on the computer or other programmable device for implementing the process Figure 1 one process or multiple processes and / or blocks Figure 1 steps for the functions specified in one block or multiple blocks, and different steps can be implemented by different modules.
[0174] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for preloading and caching web page resources, characterized in that, including: unzip the pre - installed offline package to the local cache directory when the client is started for the first time; request to download the cache configuration file when the client starts. Among them, download the resource file of the specified URL to the local cache directory and write the md5 value of the downloaded resource to the local cache; create a webview instance pool. Among them, create multiple webview instances for reuse when the client starts.
2. The method for preloading and caching web page resources according to claim 1, wherein When unzipping the pre - installed offline package to the local cache directory for the first time when starting the client, the pre - installed offline package includes a zip package. The zip package is stored in the client's own directory. The zip package contains static resources that need to be pre - loaded. When the pre - loaded static resources are updated, write the updated static resource URL and the md5 value corresponding to the resource to the cache configuration file.
3. The method for preloading and caching web page resources according to claim 1, characterized in that, When unzipping the pre - installed offline package to the local cache directory for the first time when starting the client, delete the pre - installed offline package after unzipping it.
4. The method for preloading and caching web page resources according to claim 1, characterized in that, In the method for pre - loading and caching web page resources, there is a cache generation mechanism. The cache generation mechanism includes at least one of the following tasks: pre - installed offline package, downloaded resources, writing to the local cache directory, updating the cache index, and clearing the cache.
5. The method for preloading and caching web page resources according to claim 1, wherein In the method for pre - loading and caching web page resources, there is a cache update mechanism. The cache update timing is when the client starts and when a webview is created. The cache update mechanism includes: a cache configuration file update mechanism; In the cache configuration file update mechanism, when the client is opened again, send a request to the network to check if the configuration file has been updated. If a 304 response is received, it means the configuration file has not been updated. If a 200 response is received, it means the configuration file has been updated, and download the configuration file to the local. Among them, compare the md5 value of the content of the downloaded configuration file with the md5 value in the local cache to determine if the static resources have been updated.
6. The method for preloading and caching web page resources according to any one of claims 1-5, characterized in that, The method for pre - loading and caching web page resources further includes: When accessing a web page, the SDK retrieves a webview and requests the cache configuration file; determine whether the cache needs to be updated, and at the same time intercept the network resource requests initiated by the web page. If the cache is hit, obtain the resources from the cache, otherwise obtain the resources through the network.
7. The method for preloading and caching web page resources according to claim 6, wherein The interception of the network resource requests initiated by the web page includes: judge whether the resource is in the local cache configuration file. If not, end the resource interception; if it exists, then judge whether the md5 value corresponding to the resource is cached locally. If so, perform resource interception, otherwise end the resource interception; read the cached resources. If the reading is successful, return the resources. If the reading fails, download the resources through the network.
8. A device for preloading and caching web resources, characterized in that, including: an extraction module for unzipping the pre - installed offline package to the local cache directory when the client is started for the first time; a request module for requesting to download the cache configuration file when the client starts. Among them, download the resource file of the specified URL to the local cache directory and write the md5 value of the downloaded resource to the local cache; and a creation module for creating a webview instance pool. Among them, create multiple webview instances for reuse when the client starts.
9. An electronic device, characterized in that, including the following steps: a memory; and a processor; Among them, the memory is used to store one or more computer instructions; the one or more computer instructions are executed by the processor to implement the method described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that, Computer instructions are stored on the readable storage medium; among them, when the computer instructions are executed by the processor, the method described in any one of claims 1 to 7 is implemented.