Detailed Description
Fig. 1 shows a flowchart of an HTML document processing method provided in an exemplary embodiment, which may be applied to various types of electronic devices (e.g., a server, a user equipment UE, a terminal device, etc.). As shown in fig. 1, in one embodiment, the method includes the following steps 101 to 107, wherein:
in step 101, the HTML tag containing the style attribute item existing in the HTML file to be processed is determined.
In one application scenario, the HTML files to be processed may exist on the web server, so that the HTML files to be processed are downloaded one by one from the web server. In another application scenario, the HTML file to be processed may also be an HTML file written by a developer, and the HTML file to be processed may be uploaded by the developer. Regarding the application scenario, no limitations are made herein.
The markup tags of hypertext markup language are commonly referred to as "HTML tags," which are generally enclosed by angle brackets "<", ">". Examples of HTML tags are as follows:
<a style="color:red;background:white;"/>、<b/>、<html>、......。
the HTML tag containing a style attribute item described herein may generally refer to an HTML tag containing the keyword "style", such as: red, color; background, white; "/>.
Wherein each style attribute item may include a style attribute and a style attribute value. Red in < a style ═ color; background, white; in "/>, the style property item includes: color, red and background, wherein color and background are style attributes, and red and background are style attribute values corresponding to the style attributes.
For any HTML file to be processed, step 101 may be implemented by reading the content of the HTML file, determining which HTML tags containing style attribute items exist in the content, and finally selecting the HTML tags.
In step 103, according to the HTML tag determined in step 101, a target style attribute item appearing in at least two HTML tags is determined.
In order to achieve the compression of the size of the HTML file, it is necessary to find out that there are repeated style attribute items (i.e., target style attribute items appearing in at least two HTML tags) in the HTML file to be processed through step 103.
In one embodiment, step 103 may be implemented by the following process:
step 1031: and splitting the HTML tags one by one according to the style attribute items.
In one example, assume that the HTML tags determined in step 101 are as follows:
<a style="background:red;position:absolute;color:white;"/>
<b style="background:red;position:absolute;color:blue;"/>
<c style="position:absolute;color:white;"/>
the results obtained by the resolution are as follows:
"background:red"、"position:absolute"、"color:white"、"background:red"、"position:absolute"、"color:blue"、"position:absolute"、"color:white"。
step 1033: and generating a statistical array corresponding to each style attribute item according to the splitting result, wherein the value in the statistical array is used for indicating the tag identification corresponding to the HTML tag containing the style attribute item.
If continuing with the above example, if the split result is stored as styleMap, then:
as can be seen, the statistical array corresponding to 'background: red' is: [ AEgment, BEgment ], the statistical array corresponding to 'position: absolute' is: [ AEgment, BELEMENT, CELEMENT ], the statistical array corresponding to 'color: white' is: [ AEgment, CELEMENT ], the statistical array corresponding to 'color: blue' is: [ BELEMENT ].
Step 1035: and screening a target statistic array containing at least two values from the generated statistic arrays, and determining the style attribute item corresponding to the screened target statistic array as a target style attribute item.
If the above example is continued, the results of the final screening may be:
wherein the target statistical array comprising at least two values is: [ AEgment, BELEMENT ], [ AELEMENT, BELEMENT, CELEMENT ], and [ AELEMENT, CELEMENT ]. The target style attribute item is: background: red, position: absolute and color: white.
In step 105, replacing the HTML tag in which the target style attribute item appears in the HTML file with a class code segment, wherein the class code segment contains an attribute item identifier corresponding to the target style attribute item.
In the above example, since the target style attribute determined in step 103 is: background: red, position: absolute and color: white, then the HTML tags where these target style attribute items appear can be determined as:
<a style="background:red;position:absolute;color:white;"/>
<b style="background:red;position:absolute;color:blue;"/>
<c style="position:absolute;color:white;"/>
in an embodiment, the step 105 may be implemented by the following processes:
step 1051: determining English letters (such as adopting single English letters to determine attribute item identifications) as attribute item identifications corresponding to the target style attribute items, wherein the attribute item identifications are used for identifying various style attribute items, and different target style attribute items correspond to different attribute item identifications.
In the above example, the attribute item identifier corresponding to "background: red" may be determined as a, the attribute item identifier corresponding to "color: white" may be determined as b, and the attribute item identifier corresponding to "position: absolute" may be determined as c.
Step 1052: and generating a class code segment containing the attribute item identification and replacing the HTML label of the target style attribute item with the class code segment.
In the above example, the HTML tag:
<a style="background:red;position:absolute;color:white;"/>
<b style="background:red;position:absolute;color:blue;"/>
<c style="position:absolute;color:white;"/>
replaced by the following class code segment:
<a class="a b c"/>
<b class="a c"style="color:blue;"/>
<c class="b c"/>
in step 107, writing an HTML element corresponding to the target style attribute item in the HTML file, wherein the HTML element contains a style tag pair and the target style attribute item and the attribute item identifier between the style tag pair.
In general, an HTML element may be represented by a pair of HMTL tags, which, if containing textual content, places the textual content between the tag pair ("start tag" and "end tag"). For style, the start tag is < style >, and the end tag is </style >.
In the above example, the HTML elements to be written are as follows:
<style>
.a{background:red}
.b{color:white}
.c{position:absolute;}
</style>
wherein each target style attribute item is separated from the corresponding attribute item identifier by a space character, and the HTML element can be added before the class code segment.
By the method, part of codes in the HTML file to be processed can be modified, and the file size of the modified HTML file is compressed compared with that of the HTML file before the HTML file is modified, so that the speed of obtaining the HTML file through a network is increased, and the response speed of the webpage is improved. In addition, by the method, the HTML file to be processed can be automatically obtained and the compressed HTML file can be automatically compressed, so that the complexity of manually modifying codes is avoided, and the workload of code writers is reduced.
Corresponding to the method, the HTML file processing device can be realized by software codes. As shown in fig. 2, in an embodiment, an HTML document processing apparatus 200 may include: a first determination unit 201, a second determination unit 202, a replacement unit 203, and an addition unit 204; wherein:
the first determination unit 201 is configured to: determining an HTML tag containing a style attribute item existing in an HTML file to be processed;
the second determination unit 202 is configured to: determining target style attribute items appearing in at least two HTML tags according to the HTML tags;
the replacement unit 203 is configured to: replacing an HTML label of the target style attribute item in the HTML file with a class code segment, wherein the class code segment comprises an attribute item identifier corresponding to the target style attribute item;
the adding unit 204 is configured to: writing an HTML element corresponding to the target style attribute item in the HTML file, wherein the HTML element comprises a style tag pair, the target style attribute item and the attribute item identification which are positioned between the style tag pair.
In an embodiment, the second determining unit 202 may include:
the splitting unit splits the HTML tags one by one according to style attribute items, wherein the style attribute items comprise style attributes and style attribute values;
the array generating unit is used for generating a statistical array corresponding to each style attribute item according to the splitting result, and the value in the statistical array is used for indicating the tag identification corresponding to the HTML tag containing the style attribute item;
and the array screening unit screens a target statistic array containing at least two values from the generated statistic arrays, and determines the style attribute item corresponding to the screened target statistic array as a target style attribute item.
In an embodiment, the replacing unit 203 may include:
the identification determining unit is used for determining English letters as the identification of the attribute item corresponding to the target style attribute item, wherein different target style attribute items correspond to different identification of the attribute item;
and the class generating unit is used for generating a class code segment containing the attribute item identification and replacing the HTML label of the target style attribute item with the class code segment.
In one embodiment, the attribute item identifier may be a single english letter.
As shown in fig. 3, one or more embodiments of the present disclosure provide an electronic device (e.g., a server or a user equipment UE) that may include a processor, an internal bus, a network interface, a memory (including a memory and a non-volatile memory), and possibly hardware required for other services. A processor may be one or more instances of a Central Processing Unit (CPU), processing unit, processing circuit, processor, Application Specific Integrated Circuit (ASIC), microprocessor, or other processing logic that may execute instructions. The processor reads the corresponding program from the nonvolatile memory into the memory and then runs the program. Of course, besides software implementation, the one or more embodiments in this specification do not exclude other implementations, such as logic devices or combinations of software and hardware, and so on, that is, the execution subject of the following processing flow is not limited to each logic unit, and may also be hardware or logic devices.
In one embodiment, the processor may be configured to:
determining an HTML tag containing a style attribute item existing in an HTML file to be processed;
determining target style attribute items appearing in at least two HTML tags according to the HTML tags;
replacing an HTML label of the target style attribute item in the HTML file with a class code segment, wherein the class code segment comprises an attribute item identifier corresponding to the target style attribute item;
writing an HTML element corresponding to the target style attribute item in the HTML file, wherein the HTML element comprises a style tag pair, the target style attribute item and the attribute item identification which are positioned between the style tag pair.
In yet another embodiment, there is also provided a computer storage medium having a computer program stored thereon, the computer program when executed by a processor implementing the steps of:
determining an HTML tag containing a style attribute item existing in an HTML file to be processed;
determining target style attribute items appearing in at least two HTML tags according to the HTML tags;
replacing an HTML label of the target style attribute item in the HTML file with a class code segment, wherein the class code segment comprises an attribute item identifier corresponding to the target style attribute item;
writing an HTML element corresponding to the target style attribute item in the HTML file, wherein the HTML element comprises a style tag pair, the target style attribute item and the attribute item identification which are positioned between the style tag pair.
The embodiments in the present specification are described in a progressive manner, and the same/similar parts in the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus embodiment, the apparatus embodiment and the storage medium embodiment, since they are substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the various elements may be implemented in the same one or more software and/or hardware implementations in implementing one or more embodiments of the present description.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include transitory computer readable media (transmyedia) such as modulated data signals and carrier waves.
It should also be noted that 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.
As will be appreciated by one skilled in the art, embodiments of one or more embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
One or more embodiments of the present description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. One or more embodiments of the specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The above description is merely exemplary of one or more embodiments of the present disclosure and is not intended to limit the scope of one or more embodiments of the present disclosure. Various modifications and alterations to one or more embodiments described herein will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of the present specification should be included in the scope of claims of one or more embodiments of the present specification.