Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In the embodiments of the present invention, the execution subject of the process is an application program running on the mobile terminal, which is referred to as a mobile application for short. The mobile application is a Hybrid App.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
Fig. 1 shows an implementation process of a page resource loading method provided by an embodiment of the present invention, where the method process includes steps S101 to S104. The specific implementation principle of each step is as follows.
S101: when a page loading event is triggered, a page loading request is intercepted, and a page address carried by the page loading request is obtained.
The moment when the mobile application loads the page resource comprises the moment when the mobile application is started and the moment when a resource selection instruction sent by a user is received in the running process of the mobile application. In the above case, the page load event is triggered. At this point, the mobile application generates a page load request. When the interceptor preset in the mobile application detects the page loading request, the page loading request is intercepted and captured, so that the page loading request cannot normally reach the destination address of the page loading request, that is, the page loading request cannot be sent to the remote server and cannot request to load the page resource on the remote network.
The page address can be, for example, a UR L (Uniform resource locator) address of a page resource stored on a remote server.
For example, the page address carried by the intercepted page load request may be: local:// www.abc.com/item/url/110640.
Preferably, the network transmission protocol corresponding to the native page resource of the mobile application is generally a file protocol, and since the file protocol cannot be identified and intercepted, the network transmission protocol corresponding to the native page resource is uniformly changed into a local protocol in the development process of the mobile application. And intercepting the page loading request only when detecting that the protocol of the page address carried by the page loading request is a local protocol.
S102: and determining a page resource plug-in matched with the site based on the site corresponding to the page address, wherein the page resource plug-in is pre-stored in an installation package of an application program.
A site represents a virtual directory that organizes, maintains, and manages multiple page resources. And according to the page address obtained in the step S101, determining an IP address part or a domain name address part in the page address as a site corresponding to the page address.
For example, in the page address http:// www.abc.com/item/url/110640, the domain name address obtained by the analysis is "www.abc.com", so the site corresponding to the page address is www.abc.com site.
In the embodiment of the invention, before the mobile application is started, the mobile application needs to be installed based on the pre-downloaded installation package of the mobile application. And storing the page resource plug-ins of the plurality of sites in the downloaded installation package. Specifically, before the installation package of the mobile application is issued, the page resources of each site related to the mobile application are integrated into an hfcache plug-in, and the hfcache plug-ins are packaged into the installation package of the mobile application.
And when the mobile application is successfully installed, acquiring each page resource plug-in from the installation package. And determining the page resource plug-in matched with the site from all the page resource plug-ins integrated in the installation package according to the plug-in name of each page resource plug-in and the site corresponding to the page loading request.
S103: and operating the page resource plug-in to obtain a plurality of locally stored static cache resources under the site.
When each hfcache plug-in unit runs, a compression packet and a cache file list corresponding to the hfcache plug-in unit are called. The file format of the compressed package includes, but is not limited to, a.zip format or a.rar format. The compressed packet contains various static cache resources of the site, such as js files, css files, pictures, audio and other files in the site. The cache file list is used for recording resource names of all static cache resources in the compressed package and an MD5 value corresponding to each static cache resource. Each static cache resource will compute its MD5 value through a pre-set algorithm when it is issued. In the process of integrating the static cache resources into the hfcache plug-in, the MD5 value is recorded in the cache file list corresponding to the hfcache plug-in.
And decompressing the compressed packet corresponding to the hfcache plug-in, so as to obtain the static cache resources under each storage path.
S104: and loading the static cache resources matched with the page addresses in the application program according to a preset network view.
And analyzing a resource path and a resource file name of the page resource required to be loaded by the current mobile application from the page address carried by the page loading request. And determining the static cache resources matched with the resource path and the resource file name in each static cache resource obtained by decompression.
WebView is a webkit-based engine and controls for rendering web pages. In the embodiment of the invention, the determined static cache resources are analyzed through the WebView preset in the mobile application to generate the corresponding Web page, so that the page resources required by the page loading request are displayed.
In the embodiment of the invention, the page resource plug-ins matched with the multiple sites are stored in the application program installation package of the Hybrid App, and when the Hybrid App intercepts the page loading request, the page resource plug-ins stored in the local are decompressed to load the static cache resources matched with the page loading request, so that the Hybrid App can quickly load the page resources from the local even under the condition that the page resources are loaded for the first time, the frequency of requesting the page resources from a remote server is reduced, the time consumption for loading the page resources is greatly reduced, and the performance of the Hybrid App is improved.
As another embodiment of the present invention, as shown in fig. 2, after the step S104, the method further includes:
s105: and sending a plug-in updating detection request to the first server at preset time intervals.
The static cache resources of different sites are usually maintained and updated by different teams, and in order to facilitate mobile application to update the locally stored static cache resources of each site, the embodiment of the invention provides a static cache resource publishing platform. And after the page resource plug-in is uploaded to the static cache resource publishing platform, the updating and publishing of the page resource plug-in is completed. For ease of understanding and distinction from the remote servers mentioned below, the static caching resource publishing platform described above is referred to as the first server.
The mobile application sends a plug-in update detection request to the first server at intervals of a preset time interval so as to detect whether the locally stored static cache resources are updated at the current moment.
As an embodiment of the present invention, the step S105 specifically includes:
sending a plug-in updating detection request to a first server at a preset time interval, wherein the plug-in updating detection request comprises an identification number of the page resource plug-in, so that the first server extracts the static cache resource issued at the current moment from a plug-in resource page bound with the identification number, and returns the first cache file list related to the static cache resource.
In the embodiment of the invention, each locally stored page resource plug-in is pre-allocated with an identification number, namely an ID number for uniquely identifying the page resource plug-in. And at every preset time interval, the mobile application needs to determine whether each page resource plug-in has a new version. Based on the ID number of the page resource plug-in needing to be detected, the mobile application sends a plug-in update detection request carrying the ID number to the first server.
When the first server receives the plug-in updating detection request, the ID number of the page resource plug-in carried by the plug-in updating detection request is analyzed. And the first server screens out the page resource plug-ins corresponding to the ID number from all the page resource plug-ins issued at the current moment. According to the static cache resources called by the screened page resource plug-in, the first server generates a first cache file list so as to record the resource names and the MD5 values of all the static cache resources in the first cache file list, and returns the first cache file list to the mobile application as response information of the plug-in update detection request.
Preferably, the first server stores resource homepage addresses corresponding to the ID numbers, and when the preset time interval is reached, the first server crawls page resources in the resource homepage addresses according to the stored resource homepage addresses, integrates crawling results into a new page resource plug-in, and issues the page resource plug-in. In the embodiment of the invention, the manager of the site does not need to manually log in the static cache resource publishing platform and manually upload the updated page resource plug-in, and only needs to store the resource homepage address of the site in the first server, so that the automatic crawling and the timed updating of the page resource plug-in can be realized, and the operation complexity of the page resource plug-in the updating and publishing process is reduced.
S106: and receiving a first cache file list returned by the first server according to the plug-in update detection request, wherein the first cache file list comprises the MD5 value of each static cache resource.
S107: and reading the MD5 value of each static cache resource in a second cache file list obtained by running the page resource plug-in.
After the locally stored page resource plug-in is operated, a cache file list can be obtained as well, and in order to distinguish from the cache file list returned by the first server, the cache file list obtained after the locally stored page resource plug-in is operated is called a second cache file list. In step S103, the second cache file list records resource names of the static cache resources in the compressed package corresponding to the page resource plug-in and MD5 values corresponding to each static cache resource.
S108: for each static cache resource, if the MD5 value in the first cache file list is different from the MD5 value in the second cache file list, updating the static cache resource, and updating the second cache file list to the first cache file list.
And sequentially reading the MD5 value corresponding to each resource name in the first cache file list. When the MD5 value corresponding to each resource name is read, the MD5 value corresponding to the resource name is found in the second cache file list. If the values of the two MD5 are not the same, it is determined that the static cache resource corresponding to the resource name issues a new version.
Specifically, if a certain resource name in the first cache file list does not exist in the second cache file list, it is also determined that the static cache resource corresponding to the resource name issues a new version.
And when determining that a certain static cache resource issues a new version, downloading the static cache resource from the first server to update the static cache resource stored locally by the mobile application. And deleting the first cache file list originally stored by the mobile application so as to update the second cache file list into the first cache file list.
Preferably, when the static cache resource locally stored by the mobile application is updated, only the incremental part data of the static cache resource is downloaded from the first server, so as to reduce the data amount required to be downloaded by the mobile application, thereby improving the updating efficiency of the static cache resource.
In the embodiment of the invention, whether the static cache resource in the mobile application issues a new version can be rapidly detected by regularly acquiring the first cache file list related to the newly issued static cache resource and judging whether the MD5 value of the static cache resource in the second locally stored cache file list is the same as the MD5 value in the first cache file list, so that the detection efficiency is improved; when the MD5 value of a certain static cache resource in the first cache file list is different from the MD5 value of the certain static cache resource in the second cache file list, the static cache resource is updated, so that the downloading of the whole page resource plug-in with large information amount can be avoided, and the updating efficiency of the static cache resource is improved.
As another embodiment of the present invention, as shown in fig. 3, after S103, the method further includes:
s109: and acquiring a preset decryption algorithm.
S110: and decrypting the plurality of locally stored static cache resources under the site through the decryption algorithm.
In the embodiment of the invention, the page resource plug-ins packaged into the installation package of the mobile application, the static cache resources corresponding to each page resource plug-in and the cache file list are all file data encrypted based on an Advanced Encryption Standard (AES). When the mobile application is in the running state and a page loading request is intercepted, a decryption algorithm obtaining event is triggered to read a decryption algorithm pre-stored in the mobile application. And decrypting each encrypted static cache resource through the decryption algorithm to decrypt the compressed packet, the cache file list and each static cache resource corresponding to the page resource plug-in.
In the embodiment of the invention, when the page resource plug-in and the application program are packaged, the static cache resources and other data files are encrypted, so that the static cache resources can be stored in the mobile terminal in an encrypted form. The page loading request is intercepted only when the mobile application runs, and the decryption algorithm for decrypting the page resource plug-in can be obtained, so that even if the static cache resource is intercepted by other lawless persons, the static cache resource cannot be decrypted as long as the mobile application is not in a running state, and the code safety of the static cache resource is ensured.
As an embodiment of the present invention, as shown in fig. 5, the S104 specifically includes:
s1041: and acquiring the static cache resources matched with the page address from the plurality of static cache resources, and calculating the MD5 value of the static cache resources.
In the embodiment of the invention, according to the page address carried by the page loading request, the static cache resource matched with the page address is searched in each decompressed static cache resource. And processing the searched static cache resources through an MD5 algorithm prestored in the local to calculate the MD5 value of the static cache resources at the current moment. Wherein the locally stored MD5 algorithm is the same as the MD5 algorithm used by the first server in distributing the page resource plug-ins.
S1042: and reading the MD5 value corresponding to the static cache resource from the MD5 values recorded in the second cache file list in advance.
According to the resource name of the static cache resource, the MD5 value corresponding to the resource name is searched in a locally stored cache file list to determine whether the MD5 value obtained by searching is the same as the MD5 value calculated in real time at the current moment.
S1043: and if the read MD5 value is the same as the calculated MD5 value, loading the static cache resource in the application program according to a preset network view.
S1044: and if the read MD5 value is different from the calculated MD5 value, sending the page loading request to a second server to load the network page resource based on the page address.
Different data contents, which have different MD5 values calculated by the same MD5 algorithm. Therefore, if the static cache resource stored locally at the current time is changed, or the MD5 value of the static cache resource recorded in the cache file list is the latest published MD5 value, the MD5 value calculated by the MD5 algorithm is different from the MD5 value stored in the cache file list, so that it can be determined whether the locally stored static cache resource is tampered or is the latest version of page resource.
If the MD5 value obtained by calculation is the same as the MD5 value read from the second cache file list, it can be determined that the locally stored static cache resource is the latest issued page resource and has not been tampered with, so that the static cache resource is directly loaded through the preset WebView.
If the MD5 value obtained by calculation is different from the MD5 value read from the second cache file list, it can be determined that the locally stored static cache resource is an old version of a page resource or has been illegally tampered. At the moment, the intercepted page loading request is sent to the resource server corresponding to the carried page address again to request for online acquisition of page resources.
In the embodiment of the invention, the real-time MD5 value of the static cache resource is calculated by using an MD5 algorithm, and whether the MD5 value is the same as the MD5 value in the cache file list is compared, so that the tamper-proof check of the static cache resource is realized; because the cache file list may be updated before the files of the static cache resources, if the MD5 value obtained by calculation is different from the MD5 value in the cache file list, it may be preliminarily determined that the locally stored static cache resources may be different from the static cache resources of the latest version, so that by online loading the page resources in real time, the mobile application is ensured to be able to maximally increase the loading speed of the page resources, and the page resources of the latest version are displayed, thereby improving the reliability of the mobile application.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Corresponding to the page resource loading method described in the foregoing embodiment, fig. 5 shows a structural block diagram of a page resource loading apparatus provided in the embodiment of the present invention, and for convenience of description, only a part related to the embodiment of the present invention is shown.
Referring to fig. 5, the apparatus includes:
the intercepting unit 501 is configured to intercept a page loading request when a page loading event is triggered, and obtain a page address carried by the page loading request.
A determining unit 502, configured to determine, based on the site corresponding to the page address, a page resource plug-in matched with the site, where the page resource plug-in is stored in an installation package of an application in advance.
The decompressing unit 503 is configured to run the page resource plug-in to obtain a plurality of locally stored static cache resources under the site.
A loading unit 504, configured to load, in the application program, the static cache resource that is matched with the page address according to a preset network view.
Optionally, as shown in fig. 6, the page resource loading apparatus further includes:
a requesting unit 505, configured to send a plug-in update detection request to the first server at preset time intervals.
A receiving unit 506, configured to receive a first cache file list returned by the first server according to the plug-in update detection request, where the first cache file list includes an MD5 value of each static cache resource.
The reading unit 507 is configured to read an MD5 value of each static cache resource in a second cache file list obtained by running the page resource plug-in.
An updating unit 508, configured to, for each static cache resource, if the MD5 value in the first cache file list is different from the MD5 value in the second cache file list, update the static cache resource and update the second cache file list to the first cache file list.
Optionally, the requesting unit 507 includes:
the request subunit is configured to send a plug-in update detection request to the first server at preset time intervals, where the plug-in update detection request includes an identification number of the page resource plug-in, so that the first server extracts a static cache resource issued at a current time from a plug-in resource page bound to the identification number, and returns the first cache file list related to the static cache resource to the first server.
Optionally, as shown in fig. 7, the page resource loading apparatus further includes:
an obtaining unit 509, configured to obtain a preset decryption algorithm.
A decryption unit 510, configured to decrypt, through the decryption algorithm, the locally stored multiple static cache resources under the site.
Optionally, the loading unit 504 includes:
and the calculating subunit is configured to obtain, from the multiple static cache resources, the static cache resource that matches the page address, and calculate an MD5 value of the static cache resource.
And an obtaining subunit, configured to read, from the MD5 values recorded in the second cache file list in advance, an MD5 value corresponding to the static cache resource.
And the loading subunit is configured to load the static cache resource according to a preset network view in the application program if the read MD5 value is the same as the calculated MD5 value.
And the sending subunit is configured to send the page loading request to a second server to load a network page resource based on the page address if the read MD5 value is different from the calculated MD5 value.
In the embodiment of the invention, the page resource plug-ins matched with the multiple sites are stored in the application program installation package of the Hybrid App, and when the Hybrid App intercepts the page loading request, the page resource plug-ins stored in the local are decompressed to load the static cache resources matched with the page loading request, so that the Hybrid App can quickly load the page resources from the local even under the condition that the page resources are loaded for the first time, the frequency of requesting the page resources from a remote server is reduced, the time consumption for loading the page resources is greatly reduced, and the performance of the Hybrid App is improved.
Fig. 8 is a schematic diagram of a terminal device according to an embodiment of the present invention. As shown in fig. 8, the terminal device 8 of this embodiment includes: a processor 80, a memory 81, and a computer program 82, such as a page resource loader, stored in the memory 81 and operable on the processor 80. The processor 80, when executing the computer program 82, implements the steps in the various embodiments of the page resource loading method described above, such as the steps 101 to 104 shown in fig. 1. Alternatively, the processor 80, when executing the computer program 82, implements the functions of the modules/units in the device embodiments, such as the functions of the units 51 to 54 shown in fig. 5.
Illustratively, the computer program 82 may be partitioned into one or more modules/units that are stored in the memory 81 and executed by the processor 80 to implement the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution of the computer program 82 in the terminal device 8.
The terminal device 8 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The terminal device may include, but is not limited to, a processor 80, a memory 81. Those skilled in the art will appreciate that fig. 8 is merely an example of a terminal device 8 and does not constitute a limitation of terminal device 8 and may include more or fewer components than shown, or some components may be combined, or different components, e.g., the terminal device may also include input-output devices, network access devices, buses, etc.
The Processor 80 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 81 includes at least one type of computer readable storage medium, and may be an internal storage unit of the terminal device 8, such as a hard disk or a memory of the terminal device 8. The memory 81 may also be an external storage device of the terminal device 8, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the terminal device 8. Further, the memory 81 may also include both an internal storage unit and an external storage device of the terminal device 8. The memory 81 is used for storing the computer program and other programs and data required by the terminal device. The memory 81 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. . Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.