Disclosure of Invention
The invention mainly aims to provide a loading method, a loading device, loading equipment and a storage medium based on a webpage, and aims to solve the technical problem of too low webpage loading speed.
In order to achieve the above object, the present invention provides a loading method based on a web page, which comprises the following steps:
acquiring a webpage access request of a user, and determining a current webpage to be accessed according to the webpage access request;
searching a resource file to be loaded corresponding to the current webpage;
extracting a static resource identifier in the resource file to be loaded, and acquiring corresponding static resource information to be loaded according to the static resource identifier;
screening the static resource information to be loaded to obtain target static resource information;
judging the type information of the target static resource information;
and inserting the target static resource information into the resource file to be loaded according to the type information, and loading the current webpage through the inserted resource file to be loaded.
Preferably, the searching for the resource file to be loaded corresponding to the current webpage includes:
acquiring entry information of the current webpage, and extracting a hypertext markup language file in the entry information;
and generating a resource file to be loaded according to the hypertext markup language file.
Preferably, the generating a resource file to be loaded according to the hypertext markup language file includes:
creating an analyzer, and analyzing the hypertext markup language file through the analyzer to obtain an analyzed file;
acquiring a root node and a root name in the analysis file;
obtaining corresponding child node content value information according to the root node and the root name;
and generating a resource file to be loaded according to the content value information of the child nodes.
Preferably, the screening the static resource information to be loaded to obtain the target static resource information includes:
acquiring capacity information of the static resource information to be loaded;
and taking the static resource information to be loaded corresponding to the capacity information which does not exceed the preset threshold value as target static resource information.
Preferably, the inserting the target static resource information into the resource file to be loaded according to the type information, and implementing loading of the current webpage through the inserted resource file to be loaded includes:
when the type of the target static resource information is Javascript resource information, compressing and mixing script tag information in the Javascript resource information to generate first tag information;
and inserting the first label information into the resource file to be loaded to obtain a first target resource file, deleting the first label reference information in the first target resource file, and loading the current webpage through the deleted first target resource file.
Preferably, the inserting the target static resource information into the resource file to be loaded according to the type information, and implementing loading of the current webpage through the inserted resource file to be loaded includes:
when the type of the target static resource information is cascading style sheet resource information, compressing style label information in the cascading style sheet resource information to generate second label information;
and inserting the second label information into the resource file to be loaded to obtain a second target resource file, deleting second label reference information in the second target resource file, and loading the current webpage through the deleted second target resource file.
Preferably, the inserting the target static resource information into the resource file to be loaded according to the type information, and implementing loading of the current webpage through the inserted resource file to be loaded includes:
when the type of the target static resource information is picture resource information, converting the picture resource information into a picture character string;
and replacing the picture source information in the picture resource information with a picture character string, inserting the picture character string into the resource file to be loaded to obtain a third target resource file, and loading the current webpage through the third target resource file.
In addition, in order to achieve the above object, the present invention further provides a loading apparatus based on a web page, including:
the acquisition module is used for acquiring a webpage access request of a user and determining a current webpage to be accessed according to the webpage access request;
the searching module is used for searching the resource file to be loaded corresponding to the current webpage;
the extraction module is used for extracting the static resource identifier in the resource file to be loaded and acquiring the corresponding static resource information to be loaded according to the static resource identifier;
the screening module is used for screening the static resource information to be loaded to obtain target static resource information;
the judging module is used for judging the type information of the target static resource information;
and the inserting module is used for inserting the target static resource information into the resource file to be loaded according to the type information and loading the current webpage through the inserted resource file to be loaded.
Furthermore, to achieve the above object, the present invention also proposes an apparatus comprising: the system comprises a memory, a processor and a webpage-based loader stored on the memory and capable of running on the processor, wherein the webpage-based loader is configured to realize the steps of the webpage-based loading method.
In addition, to achieve the above object, the present invention further provides a storage medium, where a loading program based on a web page is stored, and the loading program based on a web page, when executed by a processor, implements the steps of the loading method based on a web page as described above.
According to the loading method based on the webpage, the webpage access request of a user is obtained, and the current webpage to be accessed is determined according to the webpage access request; searching a resource file to be loaded corresponding to the current webpage; extracting a static resource identifier in the resource file to be loaded, and acquiring corresponding static resource information to be loaded according to the static resource identifier; screening the static resource information to be loaded to obtain target static resource information; judging the type information of the target static resource information; the target static resource information is inserted into the resource file to be loaded according to the type information, and the current webpage is loaded through the inserted resource file to be loaded, so that the situation that the static resource information is searched from different storage areas in batches for loading is avoided, the static resource information is directly inserted into the resource file to be loaded, when the webpage is loaded, the resource file to be loaded is directly loaded, the HTTP request frequency is reduced, and the whole page loading speed is improved.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may comprise a Display screen (Display), an input unit such as keys, and the optional user interface 1003 may also comprise a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The Memory 1005 may be a Random Access Memory (RAM) or a non-volatile Memory (e.g., a disk Memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration of the apparatus shown in fig. 1 is not intended to be limiting of the apparatus and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a storage medium, may include therein an operating system, a network communication module, a user interface module, and a web-based loader.
In the device shown in fig. 1, the network interface 1004 is mainly used for connecting an external network and performing data communication with other network devices; the user interface 1003 is mainly used for connecting user equipment and performing data communication with the equipment; the device calls the loading program based on the web page stored in the memory 1005 through the processor 1001 and executes the implementation method of the loading based on the web page provided by the embodiment of the invention.
Based on the hardware structure, the embodiment of the loading method based on the webpage is provided.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of a loading method based on a web page according to the present invention.
In a first embodiment, the method for loading based on web pages comprises the following steps:
step S10, acquiring a webpage access request of a user, and determining a current webpage to be accessed according to the webpage access request.
It should be noted that, the execution subject of this embodiment is a loading device based on a web page, and may also be other devices that can implement the same or similar functions.
It is understood that the web page access request may be a hypertext transfer protocol (HTTP) request initiated by inputting a web page to be accessed by a user, and may also be other access manners, which is not limited in this embodiment.
And step S20, searching the resource file to be loaded corresponding to the current webpage.
In this embodiment, in the process of generating the page, the corresponding resource file needs to be loaded according to the requirement of the page, so as to generate a HyperText markup Language (HTML) file or a HyperText markup Language-up Language (HTML) file, and the display of the web page is realized through the HTML file.
Step S30, extracting the static resource identification in the resource file to be loaded, and obtaining the corresponding static resource information to be loaded according to the static resource identification.
In the specific implementation, the display of the page can be realized by acquiring the static resource identifier corresponding to each content in the page to be accessed, searching the corresponding static resource information according to the static resource identifier, and loading the static resource information.
And step S40, screening the static resource information to be loaded to obtain target static resource information.
It should be noted that the to-be-loaded static resource information includes a Javascript file, a CSS file, a picture file, and the like, and may also include other static resource information.
In this embodiment, in the loading process of the page, the static resource information includes a plurality of static resource information with small capacity and is distributed in different storage areas, and when loading is performed, corresponding static resource information needs to be searched from each area for loading.
And step S50, judging the type information of the target static resource information.
It should be noted that the target static resource information includes at least one of a Javascript file, a CSS file, and a picture file, and when the target static resource information is processed, different static resource information is processed in different processing manners, so that flexibility of data processing is improved, and an application range is expanded.
Step S60, the target static resource information is inserted into the resource file to be loaded according to the type information, and the loading of the current webpage is realized through the inserted resource file to be loaded.
It should be noted that the static resource information includes a Javascript file, a CSS file, and a picture file, where the Javascript file, the CSS file, and the picture file have a mutual dependency relationship, and the browser may be sequentially loaded according to the relationship therebetween, that is, the static resource is sequentially loaded. For example, in the process of loading static resources, each static resource has a dependency relationship when being loaded, so for example, the static resources that the target web page needs to load are three static resources, namely a static resource 1, a Javascript file, a 2-target CSS file, and a 3-target picture, and the loading of the Javascript file needs to depend on the CSS file and the target picture, that is, the static resource 1 needs to be loaded on the basis that the static resources 2 and the static resources 3 are already loaded. In this case, in order to avoid an error during the loading of the static resource, when the static resource is loaded, the CSS file and the target picture need to be loaded first, and then the Javascript file needs to be loaded, so that the loading accuracy is improved.
According to the scheme, the current webpage to be accessed is determined according to the webpage access request by acquiring the webpage access request of the user; searching a resource file to be loaded corresponding to the current webpage; extracting a static resource identifier in the resource file to be loaded, and acquiring corresponding static resource information to be loaded according to the static resource identifier; screening the static resource information to be loaded to obtain target static resource information; judging the type information of the target static resource information; the target static resource information is inserted into the resource file to be loaded according to the type information, and the current webpage is loaded through the inserted resource file to be loaded, so that the situation that the static resource information is searched from different storage areas in batches for loading is avoided, the static resource information is directly inserted into the resource file to be loaded, when the webpage is loaded, the resource file to be loaded is directly loaded, the HTTP request frequency is reduced, and the whole page loading speed is improved.
Further, as shown in fig. 3, a second embodiment of the loading method based on web pages according to the present invention is proposed based on the first embodiment, and in this embodiment, the step S20 includes:
step S201, obtaining entry information of the current web page, and extracting a hypertext markup language file in the entry information.
In this embodiment, the portal HTML file is scanned and analyzed, and all the loaded static resource information, i.e., Javascript codes, CSS codes, and pictures, are found in an extensible markup Language (XML) traversal manner.
And step S202, generating a resource file to be loaded according to the hypertext markup language file.
It should be noted that, by traversing the entry HTML file corresponding to the current web page, the function loadXMLString () may be used, and the function loadXMLString () is located in the external JavaScript of the current web page and is used to load the XML file in the HTML file.
Specifically, the element is cycled through all children nodes of a node tree. Traversing a node tree often requires looping XML documents such as: when the value of each element is extracted, the process is called as traversing a node tree to obtain all the child nodes, determining which child nodes contain static resource information such as Javascript codes, target CSS codes and target pictures from the obtained child nodes, and displaying the names and values of the child nodes, such as the capacity size of a file.
Further, the step S202 includes:
creating an analyzer, analyzing the hypertext markup language file through the analyzer to obtain an analyzed file, obtaining a root node and a root name in the analyzed file, obtaining corresponding child node content value information according to the root node and the root name, and generating a resource file to be loaded according to the child node content value information to realize information extraction of the hypertext markup language file. The method is realized by the following codes:
according to the scheme provided by the embodiment, the hypertext markup language file is analyzed through the analyzer to obtain an analysis file, the analysis file is traversed to obtain information of each node, and effective analysis of each resource file is achieved.
Further, as shown in fig. 4, a third embodiment of the loading method based on web pages according to the present invention is proposed based on the first embodiment or the second embodiment, in this embodiment, the description is made based on the first embodiment, and the step S40 includes:
step S401, obtaining the capacity information of the static resource information to be loaded.
In this embodiment, because the static resource information to be loaded is obtained, the target static resource information with a smaller file can be obtained from the static resource information to be loaded according to the size of the file, and the target static resource information with a smaller file is processed, so that the amount of the loaded static resource information is reduced, and the running speed of the webpage is increased.
Step S402, taking the static resource information to be loaded corresponding to the capacity information which does not exceed the preset threshold value as target static resource information to realize the screening of the static resource information to be loaded.
Further, the step S60 includes:
when the type of the target static resource information is a Javascript file, compressing and mixing script tag information in the Javascript file to generate first tag information, inserting the first tag information into the resource file to be loaded to obtain a first target resource file, deleting first tag reference information in the first target resource file, and loading the current webpage through the deleted first target resource file.
In the specific implementation, after the Javascript file is compressed and mixed, the file content is directly inserted into the HTML file as the script tag, and the corresponding file reference script tag is deleted, so that the Javascript file is loaded, and the corresponding file reference script tag is deleted, so that the phenomenon that the webpage is loaded again in the webpage loading process and the webpage running speed is slow is avoided.
Further, the step S60 includes:
when the type of the target static resource information is a cascading style sheet file, compressing style label information in the cascading style sheet file to generate second label information, inserting the second label information into the resource file to be loaded to obtain a second target resource file, deleting second label reference information in the second target resource file, and loading the current webpage through the deleted second target resource file.
In the specific implementation, after the CSS file is compressed, the file content is directly inserted into the HTML file as a style tag, and the corresponding file reference style tag is deleted, so that loading of the CSS file is realized, the corresponding file reference style tag is deleted, and the phenomenon that the webpage is loaded again in the webpage loading process and the webpage running speed is slow is avoided.
Further, the step S60 includes:
and when the type of the target static resource information is a picture file, converting the picture file into a picture character string, replacing picture source information in the picture file with the picture character string, inserting the picture character string into the resource file to be loaded to obtain a third target resource file, and loading the current webpage through the third target resource file.
In a specific implementation, after being compressed appropriately, the picture file is converted into a Base64 picture character string, and the picture source information of the original img label is replaced from the picture address to the Base64 picture content.
It should be noted that, different resource files are compressed in different ways, Javascript files are compressed in a confusing and compressing manner, such as UglifyJS, CSS files are line-feed by removing spaces, and pictures are generally converted into a base64 plain text format, which is not compressed but only transcoded.
According to the scheme provided by the embodiment, the Javascript file, the CSS file and the picture file are loaded into the resource file, and when the webpage is loaded, the resource file to be loaded is directly loaded, so that the HTTP request frequency is reduced, and the whole page loading speed is increased.
The invention further provides a loading device based on the webpage.
Referring to fig. 5, fig. 5 is a functional module diagram of a loading device based on web pages according to a first embodiment of the present invention.
In a first embodiment of the loading apparatus based on web pages of the present invention, the loading apparatus based on web pages includes:
the acquiring module 10 is configured to acquire a web page access request of a user, and determine a current web page to be accessed according to the web page access request.
It is understood that the web page access request may be a hypertext transfer protocol (HTTP) request initiated by inputting a web page to be accessed by a user, and may also be other access manners, which is not limited in this embodiment.
And the searching module 20 is configured to search for the resource file to be loaded corresponding to the current webpage.
In this embodiment, in the process of generating the page, the corresponding resource file needs to be loaded according to the requirement of the page, so as to generate a HyperText markup Language (HTML) file or a HyperText markup Language-up Language (HTML) file, and the display of the web page is realized through the HTML file.
The extracting module 30 is configured to extract the static resource identifier in the resource file to be loaded, and obtain corresponding static resource information to be loaded according to the static resource identifier;
in the specific implementation, the display of the page can be realized by acquiring the static resource identifier corresponding to each content in the page to be accessed, searching the corresponding static resource information according to the static resource identifier, and loading the static resource information.
And the screening module 40 is configured to acquire the static resource information to be loaded in the resource file to be loaded, and screen the static resource information to be loaded to obtain target static resource information.
It should be noted that the to-be-loaded static resource information includes a Javascript file, a CSS file, a picture file, and the like, and may also include other static resource information.
In this embodiment, in the loading process of the page, the static resource information includes a plurality of static resource information with small capacity and is distributed in different storage areas, and when loading is performed, corresponding static resource information needs to be searched from each area for loading.
And the judging module 50 is configured to judge the type information of the target static resource information.
It should be noted that the target static resource information includes at least one of a Javascript file, a CSS file, and a picture file, and when the target static resource information is processed, different static resource information is processed in different processing manners, so that flexibility of data processing is improved, and an application range is expanded.
And the inserting module 60 is configured to insert the target static resource information into the resource file to be loaded according to the type information, and load the current webpage through the inserted resource file to be loaded.
It should be noted that the static resource information includes a Javascript file, a CSS file, and a picture file, where the Javascript file, the CSS file, and the picture file have a mutual dependency relationship, and the browser may be sequentially loaded according to the relationship therebetween, that is, the static resource is sequentially loaded. For example, in the process of loading static resources, each static resource has a dependency relationship when being loaded, so for example, the static resources that the target web page needs to load are three static resources, namely a static resource 1, a Javascript file, a 2-target CSS file, and a 3-target picture, and the loading of the Javascript file needs to depend on the CSS file and the target picture, that is, the static resource 1 needs to be loaded on the basis that the static resources 2 and the static resources 3 are already loaded. In this case, in order to avoid an error during the loading of the static resource, when the static resource is loaded, the CSS file and the target picture need to be loaded first, and then the Javascript file needs to be loaded, so that the loading accuracy is improved.
According to the scheme, the current webpage to be accessed is determined according to the webpage access request by acquiring the webpage access request of the user; searching a resource file to be loaded corresponding to the current webpage; extracting a static resource identifier in the resource file to be loaded, and acquiring corresponding static resource information to be loaded according to the static resource identifier; screening the static resource information to be loaded to obtain target static resource information; judging the type information of the target static resource information; the target static resource information is inserted into the resource file to be loaded according to the type information, and the current webpage is loaded through the inserted resource file to be loaded, so that the situation that the static resource information is searched from different storage areas in batches for loading is avoided, the static resource information is directly inserted into the resource file to be loaded, when the webpage is loaded, the resource file to be loaded is directly loaded, the HTTP request frequency is reduced, and the whole page loading speed is improved.
Other embodiments or specific implementation manners of the loading device based on the web page according to the present invention may refer to the above method embodiments, and are not described herein again.
In addition, an embodiment of the present invention further provides a storage medium, where a loading program based on a web page is stored on the storage medium, and the loading program based on the web page is executed by a processor to perform the steps of the loading method based on the web page as described above.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a computer-readable storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above, and includes several instructions for enabling an intelligent terminal (which may be a mobile phone, a computer, a terminal, an air conditioner, or a network terminal) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.