Page loading method, device, terminal equipment and storage medium based on offline package
By determining whether the loading can be accelerated when the mobile client receives a page loading request, intercepting and replacing the URL, and finding the offline package loading page, the problem of low loading efficiency of H5 pages is solved, and faster and more accurate page loading and better user experience is achieved.
Patent Information
- Application Number
- CN202011133908.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-21
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2040-10-21
AI Technical Summary
Mobile clients are easily affected by network quality when loading H5 pages, resulting in too long loading time or failure to load, especially when CSS and JS files are large, the page is stuck, affecting the user experience.
By receiving page loading requests, we can determine whether the page can be loaded faster, intercept the page's URL, replace the URL with an absolute path according to the preset replacement rules, use this absolute path to find offline packages locally and load the page.
It effectively solves the problem of too long page loading time, improves page loading efficiency and accuracy, saves data traffic, and improves user experience.
Smart Images

Figure CN112256989B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a page loading method, device, terminal equipment and storage medium based on an offline package. Background Art
[0002] H5 (html5) is a hypertext markup language with the advantages of cross-platform, easy development, high efficiency, and convenient debugging. When loading H5 pages, mobile clients are easily affected by network quality. If the network quality is poor, it will take a long time to load or fail to load.
[0003] In the prior art, resources are generally compressed and then the resource loading method is optimized, for example, images displayed on the screen can be loaded first, and the loading of places outside the screen can be delayed. However, the inventors realized that some CSS and JS file resources must be loaded completely before they can be used normally, so they must be loaded all at once in priority. However, if the CSS and JS files are large, the page will still get stuck, resulting in low H5 page loading efficiency, and will also consume more data traffic, affecting the user experience. Summary of the invention
[0004] In view of the above, it is necessary to propose a page loading method, apparatus, terminal device and storage medium based on an offline package, which can improve the efficiency of page loading.
[0005] A first aspect of the present invention provides a page loading method based on an offline package, the method comprising:
[0006] Receiving a page loading request and determining whether the page can be loaded faster according to the loading request;
[0007] When it is determined according to the loading request that the page can be loaded faster, intercepting the first URL of the page using a uniform resource locator prefix function;
[0008] Replacing the first URL of the page with the second URL according to a preset replacement rule;
[0009] Using a pre-specified class method to update the second URL to obtain the absolute path of the resource of the page;
[0010] Use the absolute path to search for the offline package locally;
[0011] When the offline package is found, the page is loaded according to the resources in the offline package.
[0012] Optionally, judging whether the page can be loaded faster according to the loading request includes:
[0013] Parsing the loading request to obtain parameter information of the page;
[0014] Identify whether a field in the parameter information is a preset field;
[0015] When the field in the parameter information is the preset field, determining that the page can be loaded faster;
[0016] When the field in the parameter information is not the preset field, it is determined that the page cannot be loaded faster.
[0017] Optionally, before receiving the page loading request, the method further includes:
[0018] Pull the download address of the compressed package through the specified interface;
[0019] Start the download process and download the compressed package according to the download address;
[0020] Decompressing the compressed package into a local sandbox to obtain parameter information of a page capable of accelerating loading and multiple resources and paths of the resources;
[0021] The parameter information and multiple resources and paths of the resources are stored in a preset database table.
[0022] Optionally, replacing the first URL of the page with the second URL according to a preset replacement rule includes:
[0023] Get the prefix of the specified class;
[0024] The second URL is obtained by replacing the hypertext transfer protocol in the first URL with the prefix of the specified class.
[0025] Optionally, the updating of the second URL using a method of a pre-specified class to obtain an absolute path of the resource of the page includes:
[0026] In the callback method of the specified class, the prefix of the second URL is replaced with the hypertext transfer protocol to obtain the original URL;
[0027] Delete the base URL in the original URL to obtain the relative path of the resource;
[0028] The relative path is concatenated with the sandbox path of the local sandbox to obtain the absolute path of the resource.
[0029] Optionally, the method further includes:
[0030] Calculating a first hash value of the resource in the offline package;
[0031] Obtaining the latest resource corresponding to the offline package on the application server and calculating a second hash value of the latest resource;
[0032] Determining whether the first hash value and the second hash value are the same;
[0033] When the first hash value and the second hash value are different, downloading the latest resource from the application server;
[0034] The page is loaded according to the latest resource.
[0035] Optionally, before calculating the first hash value of the resources in the offline package, the method further includes: determining whether a trigger condition for online update of the resources is met, the trigger condition including: one or more of an application being started, an application entering the foreground, and the time since the last update of the application exceeding a preset threshold; when the trigger condition for online update of the resources is met, calculating the first hash value of the resources in the offline package.
[0036] A second aspect of the present invention provides a page loading device based on an offline package, the device comprising:
[0037] A judgment module, used for receiving a page loading request and judging whether the page can be loaded faster according to the loading request;
[0038] A registration module, configured to intercept a first URL of the page using a uniform resource locator prefix function when it is determined that the page can be loaded faster according to the loading request;
[0039] A replacement module, used to replace the first URL of the page with a second URL according to a preset replacement rule;
[0040] An updating module, used to update the second URL using a method of a pre-specified class to obtain an absolute path of the resource of the page;
[0041] A search module, used to search for the offline package locally using the absolute path;
[0042] The loading module is used to load the page according to the resources in the offline package when the offline package is found.
[0043] A third aspect of the present invention provides a terminal device, the terminal device comprising a processor, the processor being configured to implement the offline package-based page loading method when executing a computer program stored in a memory.
[0044] A fourth aspect of the present invention provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the page loading method based on an offline package is implemented.
[0045] In summary, the offline package-based page loading method, device, terminal device and storage medium described in the present invention, when receiving a page loading request, first determine whether the page can be loaded faster according to the loading request; when it is determined that the page can be loaded faster according to the loading request, intercept the first URL of the page using a uniform resource locator prefix function; replace the first URL of the page with a second URL according to a preset replacement rule; update the second URL using a method of a pre-specified class to obtain an absolute path of the resources of the page; use the absolute path to search for an offline package locally and load the page according to the resources in the offline package, effectively solving the problem of long page loading time in the prior art and improving the efficiency of page loading; by updating the first URL of the page to an absolute path and using the absolute path to search for an offline package locally to load the page, the accuracy of page loading is improved. In addition, due to the accelerated loading of page resources, data traffic can also be saved and user experience can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 This is a flow chart of a page loading method based on an offline package provided in Embodiment 1 of the present invention.
[0047] Figure 2 It is a structural diagram of a page loading device based on an offline package provided in Embodiment 2 of the present invention.
[0048] Figure 3 It is a schematic diagram of the structure of the terminal device provided in the third embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to more clearly understand the above-mentioned purpose, features and advantages of the present invention, the present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0051] The page loading method based on the offline package provided in the embodiment of the present invention is executed by the terminal device, and correspondingly, the page loading device based on the offline package runs in the terminal device.
[0052] Figure 1This is a flow chart of a page loading method based on an offline package provided in Embodiment 1 of the present invention. The page loading method based on an offline package specifically includes the following steps. According to different requirements, the order of the steps in the flow chart can be changed, and some steps can be omitted.
[0053] S11, receiving a page loading request and determining whether the page can be loaded faster according to the loading request.
[0054] When a user needs to access a page, he can initiate a page loading request through the terminal device he holds or the APP installed in the terminal device. At this time, the terminal device receives the page loading request sent by the user and starts the processing flow of the page loading request. The page in this embodiment refers to an H5 page.
[0055] In an optional embodiment, judging whether the page can be loaded faster according to the loading request includes:
[0056] Parsing the loading request to obtain parameter information of the page;
[0057] Identify whether a field in the parameter information is a preset field;
[0058] When the field in the parameter information is the preset field, determining that the page can be loaded faster;
[0059] When the field in the parameter information is not the preset field, it is determined that the page cannot be loaded faster.
[0060] The resources may include: HTML code, CSS code, JS code and static images.
[0061] When a developer is developing an APP, he will determine whether the page needs to be loaded faster based on the size of the resources on the page in the APP. When the resources on a page are large (for example, a picture is larger than 10M), the page is marked as accelerated loading. When the resources on a page are small, the page is marked as normal loading. When the terminal device receives a page loading request, it can obtain the parameter information of the page to be loaded (for example, page name, page ID, etc.) by parsing the loading request. The terminal device first identifies whether the field in the parameter information is a preset field through a local pre-set database table, thereby determining whether the page can be loaded faster. Among them, the preset field can be a preset name, preset ID, etc.
[0062] In an optional embodiment, after determining that the page cannot be loaded in an accelerated manner, the page may be loaded in a common loading manner, that is, the page resources are obtained from an application server to load the page.
[0063] In an optional embodiment, before receiving the page loading request, the method further includes:
[0064] Pull the download address of the compressed package through the specified interface;
[0065] Start the download process to download the compressed package according to the download address;
[0066] Decompressing the compressed package into a local sandbox to obtain parameter information of a page capable of accelerating loading and multiple resources and paths of the resources;
[0067] The parameter information and multiple resources and paths of the resources are stored in a preset database table.
[0068] The APP server obtains resources of pages that can accelerate loading through a web crawler or other means, compresses the resources of pages that can accelerate loading into a compressed package, and stores them in a unified folder, wherein the path of the folder is consistent with the path of the resources of the pages that can accelerate loading.
[0069] The terminal device pulls the download address of the compressed package through the specified interface, and can delay downloading, control concurrency, etc. through the parameters of the specified interface. Among them, the specified interface refers to the interface for communication between the terminal device and the APP server.
[0070] S12: When it is determined according to the loading request that the page can be loaded faster, a first URL of the page is intercepted using a uniform resource locator prefix function.
[0071] The uniform resource locator prefix function may be a URLSchemeHandler function.
[0072] When installing, the APP in the terminal device can register its own uniform resource locator prefix function in the system to facilitate mutual calls with other APPs. The uniform resource locator prefix function uniquely identifies an APP. When implementing it, first add the URL type in the configuration file info.plist, and then add the uniform resource locator prefix to the URL type.
[0073] In order to avoid loading errors when loading HTTP protocol web pages, the terminal device intercepts HTTP protocol web pages through the URLSchemeHandler function. The APP in the terminal device also pre-specifies a class when registering its own uniform resource locator prefix function. The prefix of the specified class is a pre-defined string, such as paminawebcache.
[0074] The function of URLSchemeHandler is that developers can pass the prefix of the specified class and the class that handles this prefix to wkwebview. When the prefix in front of the URL of the link, request, or loaded resource in wkweview is consistent with the specified prefix, the system will automatically load multiple callback methods of the corresponding class, which can be startURLSchemeTask and stopURLSchemeTask methods.
[0075] S13: Replace the first URL of the page with the second URL according to a preset replacement rule.
[0076] The preset replacement rule is a preset rule for replacing a first URL of a webpage of HTTP protocol with a second URL of non-HTTP protocol.
[0077] In an optional embodiment, replacing the first URL of the page with the second URL according to a preset replacement rule includes:
[0078] Get the prefix of the specified class;
[0079] The second URL is obtained by replacing the hypertext transfer protocol in the first URL with the prefix of the specified class.
[0080] The Hypertext Transfer Protocol over Secure Socket Layer (HTTPS) is a secure HTTP channel. For example, assuming that the first URL is https: / / mina-core-stg1.pingan.com / 6525 / js / app.99ef97c5.js, the second URL obtained according to the preset replacement rule is paminawebcache: / / mina-core-stg1.pingan.com / 6525 / js / app.99ef97c5.js.
[0081] S14, using a pre-specified class method to update the second URL to obtain the absolute path of the resource of the page.
[0082] When the terminal device loads the second URL, when it is determined that the prefix of the second URL is the prefix of the specified class, the startURLSchemeTask method and the stopURLSchemeTask method in the specified class are automatically called.
[0083] In an optional embodiment, the method of using a pre-specified class to update the second URL to obtain the absolute path of the resource of the page includes:
[0084] In the callback method of the specified class, the prefix of the second URL is replaced with the hypertext transfer protocol to obtain the original URL;
[0085] Delete the base URL in the original URL to obtain the relative path of the resource;
[0086] The relative path is concatenated with the sandbox path of the local sandbox to obtain the absolute path of the resource.
[0087] The callback method may be a startURLSchemeTask method.
[0088] Since the local hard disk of the terminal device cannot recognize the second URL, it is necessary to update the second URL to obtain the absolute path so that the local hard disk can recognize the absolute path and find the offline package locally. For example, the base URL in the original URL is https: / / mina-core-stg1.pingan.com / 6525, then after triggering the startURLSchemeTask method to update the second URL, the absolute path of the resource of the page is / js / app.99ef97c5.js.
[0089] S15, using the absolute path to search for the offline package locally.
[0090] The terminal device searches the local area for offline packages through the absolute path.
[0091] S16: When the offline package is found, the page is loaded according to the resources in the offline package.
[0092] When an offline package is found locally, resources required for loading the page to be loaded are obtained from the found offline package, and a page rendering operation is performed using the page resources to complete page loading.
[0093] In an optional embodiment, when no offline package is found, the page is loaded by acquiring the resource of the page from the application server according to the first URL.
[0094] In an optional embodiment, the method may further include:
[0095] Calculating a first hash value of the resource in the offline package;
[0096] Obtaining the latest resource corresponding to the offline package on the application server and calculating a second hash value of the latest resource;
[0097] Determining whether the first hash value and the second hash value are the same;
[0098] When the first hash value and the second hash value are different, downloading the latest resource from the application server;
[0099] The page is loaded according to the latest resource.
[0100] In this optional embodiment, the hash value can be calculated by a hash function, and the hash function can include, but is not limited to, a message digest algorithm (Message Digest Algorithm, MD5). In specific implementation, the resources of the page are used as the input of MD5 to obtain an MD5 value of fixed length. The MD5 algorithm can not only ensure the accuracy and security of consistent comparison, but also greatly reduce the comparison calculation workload, thereby improving the comparison speed and user experience.
[0101] This optional embodiment can determine whether the resources of the page need to be updated by comparing the hash value of the resources in the offline package with the hash value of the latest resources; if updated, the resources are downloaded again and packaged; if not updated, the resources are no longer downloaded.
[0102] In an optional embodiment, before calculating the first hash value of the resource in the offline package, the method further includes: determining whether a trigger condition for online updating of the resource is met.
[0103] The triggering condition may include: application startup, application entering the foreground, and application last updated more than a preset threshold. When the triggering condition for online resource update is met, the first hash value of the resource in the offline package is calculated.
[0104] This optional embodiment determines whether to update resources by judging whether the triggering conditions for online resource updates are met, which can ensure the smoothness of the entire logic and avoid missing the triggering of online resource updates after the APP is running. By equipping the online update trigger mechanism, the APP can avoid too frequent verification with the APP server, which not only reduces the pressure on the APP server, but also improves the smoothness of the APP operation. In addition, in the case of non-updated resources, downloading the latest resources can achieve the purpose of local offline caching + remote online update of the application.
[0105] In summary, when receiving a page loading request, the present invention first determines whether the page can be loaded faster according to the loading request; when it is determined that the page can be loaded faster according to the loading request, the first URL of the page is intercepted using a uniform resource locator prefix function; the first URL of the page is replaced with a second URL according to a preset replacement rule; the second URL is updated using a method of a pre-specified class to obtain an absolute path of the resources of the page; the absolute path is used to search for an offline package locally and the page is loaded according to the resources in the offline package, which effectively solves the problem of long page loading time in the prior art and improves the efficiency of page loading; the page is loaded by updating the first URL of the page to an absolute path and using the absolute path to search for an offline package locally, thereby improving the accuracy of page loading. In addition, due to the accelerated loading of page resources, data traffic can be saved and the user experience can be improved.
[0106] It should be emphasized that in order to further ensure the privacy and security of the above offline package, the above offline package can be stored in the node of the blockchain.
[0107] Figure 2 It is a structural diagram of a page loading device based on an offline package provided in Embodiment 2 of the present invention.
[0108] In some embodiments, the page loading device 20 based on the offline package may include a plurality of functional modules composed of computer program segments. The computer program of each program segment in the page loading device 20 based on the offline package may be stored in the memory of the terminal device and executed by at least one processor to execute (see Figure 1 Description) Functionality for page loading based on offline packages.
[0109] In this embodiment, the page loading device 20 based on the offline package can be divided into multiple functional modules according to the functions it performs. The functional modules may include: a judgment module 201, a download module 202, a registration module 203, a replacement module 204, an update module 205, a search module 206, a loading module 207 and a calculation module 208. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0110] The determination module 201 is used to receive a page loading request and determine whether the page can be loaded faster according to the loading request.
[0111] When a user needs to access a page, he can initiate a page loading request through the terminal device he holds or the APP installed in the terminal device. At this time, the terminal device receives the page loading request sent by the user and starts the processing flow of the page loading request. The page in this embodiment refers to an H5 page.
[0112] In an optional embodiment, the determining module 201 determines whether the page can be loaded faster according to the loading request, including:
[0113] Parsing the loading request to obtain parameter information of the page;
[0114] Identify whether a field in the parameter information is a preset field;
[0115] When the field in the parameter information is the preset field, determining that the page can be loaded faster;
[0116] When the field in the parameter information is not the preset field, it is determined that the page cannot be loaded faster.
[0117] The resources may include: HTML code, CSS code, JS code and static images.
[0118] When a developer is developing an APP, he will determine whether the page needs to be loaded faster based on the size of the resources on the page in the APP. When the resources on a page are large (for example, a picture is larger than 10M), the page is marked as accelerated loading. When the resources on a page are small, the page is marked as normal loading. When the terminal device receives a page loading request, it can obtain the parameter information of the page to be loaded (for example, page name, page ID, etc.) by parsing the loading request. The terminal device first identifies whether the field in the parameter information is a preset field through a local pre-set database table, thereby determining whether the page can be loaded faster. Among them, the preset field can be a preset name, preset ID, etc.
[0119] In an optional embodiment, after determining that the page cannot be loaded in an accelerated manner, the page may be loaded in a common loading manner, that is, the page resources are obtained from an application server to load the page.
[0120] The download module 202 is used to download the compressed package before receiving the page loading request.
[0121] In an optional embodiment, the download module 202 downloads the compressed package including:
[0122] Pull the download address of the compressed package through the specified interface;
[0123] Start the download process to download the compressed package according to the download address;
[0124] Decompressing the compressed package into a local sandbox to obtain parameter information of a page capable of accelerating loading and multiple resources and paths of the resources;
[0125] The parameter information and multiple resources and paths of the resources are stored in a preset database table.
[0126] The APP server obtains resources of pages that can accelerate loading through a web crawler or other means, compresses the resources of pages that can accelerate loading into a compressed package, and stores them in a unified folder, wherein the path of the folder is consistent with the path of the resources of the pages that can accelerate loading.
[0127] The terminal device pulls the download address of the compressed package through the specified interface, and can delay downloading, control concurrency, etc. through the parameters of the specified interface. Among them, the specified interface refers to the interface for communication between the terminal device and the APP server.
[0128] The registration module 203 is used to intercept the first URL of the page using a uniform resource locator prefix function when it is determined that the page can be loaded faster according to the loading request.
[0129] The uniform resource locator prefix function may be a URLSchemeHandler function.
[0130] When installing, the APP in the terminal device can register its own uniform resource locator prefix function in the system to facilitate mutual calls with other APPs. The uniform resource locator prefix function uniquely identifies an APP. When implementing it, first add the URL type in the configuration file info.plist, and then add the uniform resource locator prefix to the URL type.
[0131] In order to avoid loading errors when loading HTTP protocol web pages, the terminal device intercepts HTTP protocol web pages through the URLSchemeHandler function. The APP in the terminal device also pre-specifies a class when registering its own uniform resource locator prefix function. The prefix of the specified class is a pre-defined string, such as paminawebcache.
[0132] The function of URLSchemeHandler is that developers can pass the prefix of the specified class and the class that handles this prefix to wkwebview. When the prefix in front of the URL of the link, request, or loaded resource in wkweview is consistent with the specified prefix, the system will automatically load multiple callback methods of the corresponding class, which can be startURLSchemeTask and stopURLSchemeTask methods.
[0133] The replacement module 204 is used to replace the first URL of the page with the second URL according to a preset replacement rule.
[0134] The preset replacement rule is a preset rule for replacing a first URL of a webpage of HTTP protocol with a second URL of non-HTTP protocol.
[0135] In an optional embodiment, the replacing module 204 replaces the first URL of the page with the second URL according to a preset replacement rule, including:
[0136] Get the prefix of the specified class;
[0137] The second URL is obtained by replacing the hypertext transfer protocol in the first URL with the prefix of the specified class.
[0138] The Hypertext Transfer Protocol over Secure Socket Layer (HTTPS) is a secure HTTP channel. For example, assuming that the first URL is https: / / mina-core-stg1.pingan.com / 6525 / js / app.99ef97c5.js, the second URL obtained according to the preset replacement rule is paminawebcache: / / mina-core-stg1.pingan.com / 6525 / js / app.99ef97c5.js.
[0139] The updating module 205 is used to update the second URL using a method of a pre-specified class to obtain an absolute path of the resource of the page.
[0140] When the terminal device loads the second URL, when it is determined that the prefix of the second URL is the prefix of the specified class, the startURLSchemeTask method and the stopURLSchemeTask method in the specified class are automatically called.
[0141] In an optional embodiment, the updating module 205 updates the second URL using a method of a pre-specified class, and the absolute path of the resource of the page is obtained, including:
[0142] In the callback method of the specified class, the prefix of the second URL is replaced with the hypertext transfer protocol to obtain the original URL;
[0143] Delete the base URL in the original URL to obtain the relative path of the resource;
[0144] The relative path is concatenated with the sandbox path of the local sandbox to obtain the absolute path of the resource.
[0145] The callback method may be a startURLSchemeTask method.
[0146] Since the local hard disk of the terminal device cannot recognize the second URL, it is necessary to update the second URL to obtain the absolute path so that the local hard disk can recognize the absolute path and find the offline package locally. For example, the base URL in the original URL is https: / / mina-core-stg1.pingan.com / 6525, then after triggering the startURLSchemeTask method to update the second URL, the absolute path of the resource of the page is / js / app.99ef97c5.js.
[0147] The search module 206 is used to use the absolute path to search for the offline package locally.
[0148] The terminal device searches the local area for offline packages through the absolute path.
[0149] The loading module 207 is used to load the page according to the resources in the offline package when an offline package is found.
[0150] When an offline package is found locally, resources required for loading the page to be loaded are obtained from the found offline package, and a page rendering operation is performed using the page resources to complete page loading.
[0151] In an optional embodiment, when no offline package is found, the page is loaded by acquiring the resource of the page from the application server according to the first URL.
[0152] The calculation module 208 is used to calculate a first hash value of the resource in the offline package; obtain the latest resource corresponding to the offline package on the application server and calculate a second hash value of the latest resource.
[0153] The determining module 201 is further configured to determine whether the first hash value and the second hash value are the same.
[0154] The downloading module 202 is further configured to download the latest resource from the application server when the first hash value and the second hash value are different.
[0155] The loading module 207 is further configured to load the page according to the latest resource.
[0156] In this optional embodiment, the hash value can be calculated by a hash function, and the hash function can include, but is not limited to, a message digest algorithm (Message Digest Algor ithm, MD5). In specific implementation, the resources of the page are used as the input of MD5 to obtain an MD5 value of a fixed length. The MD5 algorithm can not only ensure the accuracy and security of consistent comparison, but also greatly reduce the comparison calculation workload, thereby improving the comparison speed and user experience.
[0157] This optional embodiment can determine whether the resources of the page need to be updated by comparing the hash value of the resources in the offline package with the hash value of the latest resources; if updated, the resources are downloaded again and packaged; if not updated, the resources are no longer downloaded.
[0158] In an optional embodiment, the judgment module 201 is further configured to judge whether a triggering condition for online updating of resources is met before calculating the first hash value of the resources in the offline package.
[0159] The triggering condition may include: application startup, application entering the foreground, and application last updated more than a preset threshold. When the triggering condition for online resource update is met, the first hash value of the resource in the offline package is calculated.
[0160] This optional embodiment determines whether to update resources by judging whether the triggering conditions for online resource updates are met, which can ensure the smoothness of the entire logic and avoid missing the triggering of online resource updates after the APP is running. By equipping the online update trigger mechanism, the APP can avoid too frequent verification with the APP server, which not only reduces the pressure on the APP server, but also improves the smoothness of the APP operation. In addition, in the case of non-updated resources, downloading the latest resources can achieve the purpose of local offline caching + remote online update of the application.
[0161] In summary, when receiving a page loading request, the present invention first determines whether the page can be loaded faster according to the loading request; when it is determined that the page can be loaded faster according to the loading request, the first URL of the page is intercepted using a uniform resource locator prefix function; the first URL of the page is replaced with a second URL according to a preset replacement rule; the second URL is updated using a method of a pre-specified class to obtain an absolute path of the resources of the page; the absolute path is used to search for an offline package locally and the page is loaded according to the resources in the offline package, which effectively solves the problem of long page loading time in the prior art and improves the efficiency of page loading; the page is loaded by updating the first URL of the page to an absolute path and using the absolute path to search for an offline package locally, thereby improving the accuracy of page loading. In addition, due to the accelerated loading of page resources, data traffic can be saved and the user experience can be improved.
[0162] It should be emphasized that in order to further ensure the privacy and security of the above offline package, the above offline package can be stored in the node of the blockchain.
[0163] See also Figure 3 FIG. 2 is a schematic diagram of the structure of a terminal device provided in Embodiment 3 of the present invention. In a preferred embodiment of the present invention, the terminal device 3 includes a memory 31 , at least one processor 32 , at least one communication bus 33 and a transceiver 34 .
[0164] Those skilled in the art should understand that Figure 3 The structure of the terminal device shown does not constitute a limitation of the embodiments of the present invention, and may be either a bus structure or a star structure. The terminal device 3 may also include more or less other hardware or software than shown in the figure, or a different arrangement of components.
[0165] In some embodiments, the terminal device 3 is a terminal device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application-specific integrated circuits, programmable gate arrays, digital processors, and embedded devices. The terminal device 3 may also include client devices, which include but are not limited to any electronic product that can interact with a client through a keyboard, mouse, remote control, touchpad, or voice control device, such as a personal computer, tablet computer, smart phone, digital camera, etc.
[0166] It should be noted that the terminal device 3 is only an example, and other existing or future electronic products that are suitable for the present invention should also be included in the protection scope of the present invention and included here by reference.
[0167] In some embodiments, the memory 31 stores a computer program, and when the computer program is executed by the at least one processor 32, all or part of the steps in the offline package-based page loading method are implemented. The memory 31 includes a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0168] Furthermore, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the blockchain node, etc.
[0169] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0170] In some embodiments, the at least one processor 32 is the control core (ControlUnit) of the terminal device 3, and uses various interfaces and lines to connect various components of the entire terminal device 3, and executes various functions and processes data of the terminal device 3 by running or executing programs or modules stored in the memory 31, and calling data stored in the memory 31. For example, when the at least one processor 32 executes the computer program stored in the memory, it implements all or part of the steps of the page loading method based on the offline package described in the embodiment of the present invention; or implements all or part of the functions of the page loading device based on the offline package. The at least one processor 32 can be composed of an integrated circuit, for example, it can be composed of a single packaged integrated circuit, or it can be composed of multiple integrated circuits with the same function or different functions, including one or more central processing units (CPU), microprocessors, digital processing chips, graphics processors, and various control chips.
[0171] In some embodiments, the at least one communication bus 33 is configured to implement connection and communication between the memory 31 and the at least one processor 32, etc.
[0172] Although not shown, the terminal device 3 may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 32 through a power management device, so that the power management device can manage charging, discharging, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The terminal device 3 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0173] The above-mentioned integrated unit implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, and includes a number of instructions for enabling a computer device (which can be a personal computer, a terminal device, or a network device, etc.) or a processor to execute a part of the method described in each embodiment of the present invention.
[0174] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0175] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0176] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0177] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0178] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A page loading method based on an offline package, characterized in that: The method comprises: Receiving a page loading request and determining whether the page can be loaded faster according to the loading request; When it is determined according to the loading request that the page can be loaded faster, the first URL of the page is intercepted by a uniform resource locator prefix function, the uniform resource locator prefix function is used to pre-specify a class, and the specified class and the corresponding prefix are passed to the WKWebView component, so that the WKWebView component loads the callback method of the specified class when it is detected that the prefix of the first URL matches the received prefix; Replacing the first URL of the page with the second URL according to a preset replacement rule, including: replacing the HTTP protocol in the first URL with the prefix of the specified class; Using the method of the specified class to update the second URL to obtain the absolute path of the resource of the page, including: in the callback method of the specified class, replacing the prefix of the second URL with the hypertext transfer protocol to obtain the original URL, deleting the base URL in the original URL to obtain the relative path of the resource, and splicing the relative path with the sandbox path of the local sandbox to obtain the absolute path of the resource; Use the absolute path to search for the offline package locally; When the offline package is found, the page is loaded according to the resources in the offline package.
2. The page loading method based on the offline package according to claim 1, characterized in that: The determining, according to the loading request, whether the page can be loaded faster comprises: Parsing the loading request to obtain parameter information of the page; Identify whether a field in the parameter information is a preset field; When the field in the parameter information is the preset field, determining that the page can be loaded faster; When the field in the parameter information is not the preset field, it is determined that the page cannot be loaded faster.
3. The page loading method based on offline package according to claim 1, characterized in that: Before receiving the page loading request, the method further includes: Pull the download address of the compressed package through the specified interface; Start the download process to download the compressed package according to the download address; Decompressing the compressed package into a local sandbox to obtain parameter information of a page capable of accelerating loading and multiple resources and paths of the resources; The parameter information and multiple resources and paths of the resources are stored in a preset database table.
4. The page loading method based on an offline package according to any one of claims 1 to 3, characterized in that: The method further comprises: Calculating a first hash value of the resource in the offline package; Obtaining the latest resource corresponding to the offline package on the application server and calculating a second hash value of the latest resource; Determining whether the first hash value and the second hash value are the same; When the first hash value and the second hash value are different, downloading the latest resource from the application server; The page is loaded according to the latest resource.
5. The page loading method based on offline package according to claim 4, characterized in that: Before calculating the first hash value of the resource in the offline package, the method also includes: determining whether a trigger condition for online updating of the resource is met, the trigger condition including: one or more of an application being started, an application entering the foreground, and a time from the last update of the application exceeding a preset threshold; when the trigger condition for online updating of the resource is met, calculating the first hash value of the resource in the offline package.
6. A page loading device based on an offline package, the device being used to implement the page loading method based on an offline package as claimed in any one of claims 1 to 5, characterized in that: The device comprises: A judgment module, used for receiving a page loading request and judging whether the page can be loaded faster according to the loading request; A registration module, configured to intercept a first URL of the page using a uniform resource locator prefix function when it is determined that the page can be loaded faster according to the loading request; A replacement module, used to replace the first URL of the page with a second URL according to a preset replacement rule; An updating module, used to update the second URL using a method of a pre-specified class to obtain an absolute path of the resource of the page; A search module, used to search for the offline package locally using the absolute path; The loading module is used to load the page according to the resources in the offline package when the offline package is found.
7. A terminal device, characterized in that: The terminal device includes a processor, and the processor is used to implement the page loading method based on the offline package as described in any one of claims 1 to 5 when executing the computer program stored in the memory.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the page loading method based on the offline package as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method and system for browser to load internet resources
CN101763357A
Webpage resource loading method and device, electronic equipment and storage medium
CN108228818A