Front-end resource package compression method and device, electronic equipment and storage medium

文档序号:1889376 发布日期:2021-11-26 浏览:37次 中文

阅读说明:本技术 前端资源包压缩方法、装置、电子设备及存储介质 (Front-end resource package compression method and device, electronic equipment and storage medium ) 是由 黄康 于 2021-08-31 设计创作,主要内容包括:本发明涉及人工智能领域,揭露了一种前端资源包压缩方法,包括:筛选体积大于阈值的标记语言文件,得到待精简标记语言文件;利用标识符对各个待精简标记语言文件中的数据段落进行替换,得到已精简标记语言文件,将数据段落存储至json文件;对json文件进行字符串精简操作,得到精简json文件;对标记语言文件中各个层叠样式文件提取公共样式,得到公共层叠样式文件;将体积不大于阈值的各个标记语言文件与已精简标记语言文件进行排序,并将排序结果与精简json文件及公共层叠样式文件打包,得到压缩文件包。本发明还提供了一种前端资源包压缩装置、电子设备及存储介质。本发明可以降低前端资源包的数据量,增强网络适用性。(The invention relates to the field of artificial intelligence, and discloses a front-end resource packet compression method, which comprises the following steps: screening the markup language files with the volume larger than a threshold value to obtain markup language files to be simplified; replacing the data paragraphs in each markup language file to be simplified by using the identifiers to obtain a simplified markup language file, and storing the data paragraphs into a json file; carrying out character string simplification operation on the json file to obtain a simplified json file; extracting a common style from each stack style file in the markup language file to obtain a common stack style file; sequencing each markup language file with the volume not larger than the threshold value and the simplified markup language file, and packaging the sequencing result, the simplified json file and the common cascading style file to obtain a compressed file package. The invention also provides a front-end resource packet compression device, electronic equipment and a storage medium. The invention can reduce the data volume of the front-end resource packet and enhance the network applicability.)

1. A method for front-end resource packet compression, the method comprising:

screening markup language files with file volume values larger than a preset compaction threshold value from a front-end resource packet of a target application to obtain markup language files to be compacted;

acquiring data paragraphs of preset types in the markup language file to be simplified, performing one-to-one replacement on each data paragraph by using a preset unique identifier, recording a replacement corresponding relationship to obtain a simplified markup language file corresponding to the markup language file to be simplified, and storing each replaced data paragraph to a pre-constructed json file according to the replacement corresponding relationship;

according to a preset simplification strategy, field deletion and character string simplification operations are carried out on the json file to obtain a simplified json file;

according to the simplification strategy, field deletion and character string simplification operations are carried out on each cascading style file in the markup language file to obtain a simplified cascading style file, and a public style in the simplified cascading style file is extracted to obtain a public cascading style file;

sequencing each markup language file with a file volume value smaller than or equal to the simplified threshold value and each simplified markup language file in the front-end resource package according to a preset file starting sequence to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public cascading style files to obtain a compressed file package of the front-end resource package.

2. The front-end resource package compression method according to claim 1, wherein the storing each replaced data segment to a pre-constructed json file according to the replacement correspondence includes:

creating a json file by using a pre-constructed scene collaborative service, and naming the json file by using the file name of the markup language file to be simplified;

and constructing a hierarchy corresponding to the unique identifier in the json file according to the unique identifier, and storing each data paragraph under the hierarchy corresponding to the unique identifier according to the replacement correspondence.

3. The front-end resource package compression method of claim 1, wherein the reducing the json file according to a preset reduction policy to obtain a reduced json file comprises:

deleting character data related to a preset field to be deleted in the json file to obtain clean data;

constructing a global unique naming space, and carrying out name character simplification operation on each variable in the clean data by using the global unique naming space to obtain simplified data;

and identifying a source mapping file in the simplified data, and deleting the source mapping file from the simplified data to obtain the simplified json file.

4. The front-end resource package compression method of claim 1, wherein the extracting common styles in the simplified cascading style file to obtain a common cascading style file comprises:

inquiring the style class and the style declaration in the simplified cascading style file to obtain an inquiry result;

and extracting a public style class and a public style declaration from the query result to obtain the public cascading style file.

5. The method of claim 1, wherein the step of sorting each markup language file and each simplified markup language file having a file volume value less than or equal to the reduction threshold in the front-end resource package according to a preset file start sequence to obtain a configuration framework package comprises:

summarizing each markup language file and the simplified markup language file of which the file volume value is smaller than or equal to the simplified threshold value in the front-end resource package to obtain a summarized file;

partitioning the summary file by using a pre-constructed combined distribution service according to a preset front-end page content rule to obtain markup language chunks corresponding to each front-end page;

and sequentially arranging all markup language chunks according to a preset file starting sequence to obtain a configuration framework packet corresponding to the front-end resource packet.

6. The front-end resource package compression method of claim 1, wherein the step of packaging the configuration framework package, the compact json file and the common cascading style file to obtain a compressed file package of the front-end resource package comprises:

according to each unique identifier in each simplified markup language file, linking the simplified json file with the configuration framework package to obtain a configuration resource package;

and packaging the configuration resource package and the public stack style file to obtain a compressed file package of the front-end resource package.

7. The front-end resource package compression method of any one of claims 1 to 6, wherein after obtaining the compressed file package of the front-end resource package, the method further comprises:

encoding the compressed file packet by using a pre-constructed encoder to obtain encoded data;

cutting the coded data according to a preset cutting rule to obtain each coding block;

and storing each coding block into a pre-constructed database server by using a distributed algorithm.

8. An apparatus for front-end resource packet compression, the apparatus comprising:

the markup language file simplification module is used for screening markup language files with file volume values larger than a preset simplification threshold value from a front-end resource package to obtain markup language files to be simplified, acquiring data paragraphs of preset types in the markup language files to be simplified, performing one-to-one replacement on the data paragraphs by using preset unique identifiers, recording a replacement corresponding relation to obtain simplified markup language files corresponding to the markup language files to be simplified, and storing the replaced data paragraphs into a pre-constructed json file according to the replacement corresponding relation;

the json file compression module is used for carrying out field deletion and character string simplification operation on the json file according to a preset simplification strategy to obtain a simplified json file;

the public cascading style file extracting module is used for executing field deletion and character string simplification operations on each cascading style file in the markup language file according to the simplification strategy to obtain a simplified cascading style file, and extracting a public style in the simplified cascading style file to obtain a public cascading style file;

and the compressed package generation module is used for sequencing each markup language file and each simplified markup language file, the file volume value of which is less than or equal to the simplified threshold value, in the front-end resource package according to a preset file starting sequence to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public cascading style files to obtain a compressed file package of the front-end resource package.

9. An electronic device, characterized in that the electronic device comprises:

at least one processor; and the number of the first and second groups,

a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,

the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform a front end resource packet compression method as claimed in any one of claims 1 to 7.

10. A computer-readable storage medium, storing a computer program, wherein the computer program, when executed by a processor, implements the front-end resource packet compression method as claimed in any one of claims 1 to 7.

Technical Field

The present invention relates to the field of artificial intelligence, and in particular, to a front-end resource packet compression method and apparatus, an electronic device, and a computer-readable storage medium.

Background

With the development of the internet, the variety of software is increasingly abundant, and each software application gradually becomes an indispensable part in daily life of people. However, when the software application is online, and after the client completes the installation operation of the software application, the client starts the software, and particularly when the software is started for the first time, the mobile terminal device needs to execute the front-end resource package of the software first, so as to ensure the normal execution of the software application. However, the customer experience is greatly influenced by the large data volume of the front-end resource packet and the long time consumption of the loading process.

The industry generally adopts a method of splitting a front-end resource package, and starts the front-end resource package in batches, so as to reduce the waiting time of a user when logging in a software application each time, and load data of a function when the user opens the function. The method for splitting the block requires a research and development staff to perform splitting, testing and re-splitting operations on the front-end resource package of the client, and ensures that the software application can still be normally executed even if part of data is not referred. However, the method is low in efficiency, prone to leak and long in product development period.

Disclosure of Invention

The invention provides a front-end resource packet compression method, which mainly aims to reduce the data volume of a front-end resource packet and ensure that a product can be normally started in a weak network environment.

In order to achieve the above object, a front-end resource packet compression method provided by the present invention includes:

screening markup language files with file volume values larger than a preset compaction threshold value from a front-end resource package to obtain markup language files to be compacted;

acquiring data paragraphs of preset types in the markup language file to be simplified, performing one-to-one replacement on each data paragraph by using a preset unique identifier, recording a replacement corresponding relationship to obtain a simplified markup language file corresponding to the markup language file to be simplified, and storing each replaced data paragraph to a pre-constructed json file according to the replacement corresponding relationship;

according to a preset simplification strategy, field deletion and character string simplification operations are carried out on the json file to obtain a simplified json file;

according to the simplification strategy, field deletion and character string simplification operations are carried out on each cascading style file in the markup language file to obtain a simplified cascading style file, and a public style in the simplified cascading style file is extracted to obtain a public cascading style file;

sequencing each markup language file with a file volume value smaller than or equal to the simplified threshold value and each simplified markup language file in the front-end resource package according to a preset file starting sequence to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public cascading style files to obtain a compressed file package of the front-end resource package.

Optionally, the storing each replaced data segment in a pre-constructed json file includes:

creating a json file by using a pre-constructed scene collaborative service, and naming the json file by using the file name of the markup language file to be simplified;

and constructing a hierarchy corresponding to the unique identifier in the json file according to the unique identifier, and saving each data paragraph to be below the hierarchy corresponding to the unique identifier.

Optionally, the reducing the json file according to a preset reducing policy to obtain a reduced json file includes:

deleting character data related to a preset field to be deleted in the json file to obtain clean data;

constructing a global unique naming space, and carrying out name character simplification operation on each variable in the clean data by using the global unique naming space to obtain simplified data;

and identifying a source mapping file in the simplified data, and deleting the source mapping file from the simplified data to obtain the simplified json file.

Optionally, the extracting a common style in the simplified cascading style file to obtain a common cascading style file includes:

inquiring the style class and the style declaration in the simplified cascading style file to obtain an inquiry result;

and extracting a public style class and a public style declaration from the query result to obtain the public cascading style file.

Optionally, the sorting, according to a preset file start sequence, each markup language file having a file volume value smaller than or equal to the compaction threshold value in the front-end resource package and each compacted markup language file to obtain a configuration framework package, includes:

summarizing each markup language file and the simplified markup language file of which the file volume value is smaller than or equal to the simplified threshold value in the front-end resource package to obtain a summarized file;

partitioning the summary file by using a pre-constructed combined distribution service according to a preset front-end page content rule to obtain markup language chunks corresponding to each front-end page;

and sequentially arranging all markup language chunks according to a preset file starting sequence to obtain a configuration framework packet corresponding to the front-end resource packet.

Optionally, the step of packaging the configuration frame package, the simplified json file and the common cascading style file to obtain a compressed file package of the front-end resource package includes:

according to each unique identifier in each simplified markup language file, linking the simplified json file with the configuration framework package to obtain a configuration resource package;

and packaging the configuration resource package and the public stack style file to obtain a compressed file package of the front-end resource package.

Optionally, after obtaining the compressed file package of the front-end resource package, the method further includes:

encoding the compressed file packet by using a pre-constructed encoder to obtain encoded data;

cutting the coded data according to a preset cutting rule to obtain each coding block;

and storing each coding block into a pre-constructed database server by using a distributed algorithm.

In order to solve the above problem, the present invention further provides a front-end resource packet compression apparatus, including:

the markup language file simplification module is used for screening markup language files with file volume values larger than a preset simplification threshold value from a front-end resource package to obtain markup language files to be simplified, acquiring data paragraphs of preset types in the markup language files to be simplified, performing one-to-one replacement on the data paragraphs by using preset unique identifiers, recording a replacement corresponding relation to obtain simplified markup language files corresponding to the markup language files to be simplified, and storing the replaced data paragraphs into a pre-constructed json file according to the replacement corresponding relation;

the json file compression module is used for carrying out field deletion and character string simplification operation on the json file according to a preset simplification strategy to obtain a simplified json file;

the public cascading style file extracting module is used for executing field deletion and character string simplification operations on each cascading style file in the markup language file according to the simplification strategy to obtain a simplified cascading style file, and extracting a public style in the simplified cascading style file to obtain a public cascading style file;

and the compressed package generation module is used for sequencing each markup language file and each simplified markup language file, the file volume value of which is less than or equal to the simplified threshold value, in the front-end resource package according to a preset file starting sequence to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public cascading style files to obtain a compressed file package of the front-end resource package.

In order to solve the above problem, the present invention also provides an electronic device, including:

at least one processor; and the number of the first and second groups,

a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,

the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to implement the front-end resource packet compression method described above.

In order to solve the above problem, the present invention further provides a computer-readable storage medium, in which at least one computer program is stored, and the at least one computer program is executed by a processor in an electronic device to implement the front-end resource package compression method described above.

The embodiment of the invention takes a markup language file with the file volume larger than a preset compaction threshold value in a front-end resource package as a markup language file to be compacted, obtains the position of each data paragraph of a preset type recorded in the markup language file to be compacted, and marks a preset unique identifier at each position, wherein the unique identifier can link the markup language file and the json file; further, the json file is reduced into the reduced json file according to the reduction strategy, the cascading style file is reduced into the public cascading style file, and the data volume in a front-end resource package is further reduced, so that the product can be normally started under a weak network environment; meanwhile, the invention compresses through a simplification strategy, thereby greatly increasing the compression efficiency. Therefore, the front-end resource package compression method, the front-end resource package compression device, the electronic equipment and the storage medium can improve the compression efficiency of the front-end resource package in the compression process.

Drawings

Fig. 1 is a flowchart illustrating a front-end resource packet compression method according to an embodiment of the present invention;

FIG. 2 is a detailed flowchart illustrating a step of the front-end resource packet compression method provided in FIG. 1 according to a first embodiment of the present invention;

fig. 3 is a block diagram of a front-end resource packet compression apparatus according to an embodiment of the present invention;

fig. 4 is a schematic diagram of an internal structure of an electronic device implementing a front-end resource packet compression method according to an embodiment of the present invention;

the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.

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.

The embodiment of the application provides a front-end resource packet compression method. The executing body of the front-end resource package compression method includes, but is not limited to, at least one of electronic devices, such as a server and a terminal, which can be configured to execute the method provided by the embodiment of the present application. In other words, the front-end resource package compression method may be performed by software or hardware installed in the terminal device or the server device, and the software may be a block chain platform. The server side can be an independent server, and can also be a cloud server for providing basic cloud computing services such as cloud service, a cloud database, cloud computing, a cloud function, cloud storage, Network service, cloud communication, middleware service, domain name service, security service, Content Delivery Network (CDN), big data and an artificial intelligence platform.

Fig. 1 is a schematic flow chart of a front-end resource packet compression method according to an embodiment of the present invention. In the embodiment of the present invention, the front-end resource packet compression method includes:

s1, screening the markup language files with the file volume value larger than the preset compaction threshold value from the front-end resource package to obtain the markup language files to be compacted.

The front-end resource package is a collection of all files installed on the client by a preset software application, and comprises markup language files, json files and the like. In the embodiment of the invention, the Markup Language is HyperText Markup Language (html), the html file can be read by various web browsers to generate a file for transmitting various information by a web page, and the html file is mostly applied to a front-end interface of software application. The json file is a file with a lightweight data exchange format, and the json file is a file with a lightweight data exchange format, is stored and represented in a text format completely independent of a programming language, and is easy to analyze and generate by a machine.

In the embodiment of the invention, the file size of each html file in the front-end resource package is inquired to obtain the volume value of each html file; judging the relation between the volume value of each html file and a preset compaction threshold value; and judging the html file with the volume value less than or equal to the preset compaction threshold value as the html file without compaction, and judging the html file with the volume value greater than the preset compaction threshold value as the html file to be compacted.

Specifically, the html file in the front-end resource package may contain character strings in the order of ten thousand, such as various types of texts like "user protocols", and the html file containing the text has a large text volume, which is usually larger than the preset reduction threshold, wherein the reduction threshold is set to 300KB in the embodiment of the present invention.

In the embodiment of the invention, all html files in the front-end resource package are screened, and the html file with the volume value larger than 300KB is defined as the html file to be reduced. According to the embodiment of the invention, the volume value of the html file to be reduced can be reduced by reducing the html file to be reduced, so that a large amount of data does not need to be loaded when the software application is started for the first time, and the starting time is shortened.

The embodiment of the application can perform the relevant processes from S1 to S6 on the relevant data based on the artificial intelligence technology, and can greatly accelerate the compression efficiency of the front-end resource package. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.

S2, obtaining data paragraphs of preset types in the markup language file to be simplified, performing one-to-one replacement on each data paragraph by using a preset unique identifier to obtain a simplified markup language file corresponding to the markup language file to be simplified, and storing each replaced data paragraph into a pre-constructed json file.

In the embodiment of the invention, the category monitoring of all html files in the front-end resource package is realized through a pre-constructed monitoring service, and when the html files are html files which do not need to be simplified, processing is not needed; when the html file is the html file to be reduced, opening the html file to be reduced, extracting data paragraphs such as text paragraphs, videos and pictures in the closed labels according to the closed labels in the html file to be reduced, marking a globally unique identifier at a position where the data paragraphs are stored in the closed labels, and obtaining the reduced html file.

In detail, in the embodiment of the present invention, the storing each replaced data segment in a pre-constructed json file includes:

creating a json file by using a pre-constructed scene collaborative service, and naming the json file by using the file name of the markup language file to be simplified;

and constructing a hierarchy corresponding to the unique identifier in the json file according to the unique identifier, and saving each data paragraph to be below the hierarchy corresponding to the unique identifier.

In the embodiment of the invention, a json file is constructed, the json file is named as the same name as the html file to be simplified, and after the naming is finished, the unique identifier and the corresponding data paragraph are stored in the json file in a one-to-one correspondence manner.

The simplified html file and the json file both have corresponding unique identifiers, and the link between the simplified html file and the simplified json file can be established according to the unique identifiers. When the software application is started, each simplified html file is executed firstly, and only when a client queries detailed data, such as protocol content and the like, the unique identifier in the simplified html file is triggered to call the json file for loading.

And S3, according to a preset simplification strategy, carrying out field deletion and character string simplification operation on the json file to obtain a simplified json file.

In the embodiment of the present invention, the simplification policy is a simplification process execution policy preconfigured in a configuration file config.

In detail, in the embodiment of the present invention, as shown in fig. 2, the performing field deletion and character string reduction on the json file according to a preset reduction policy to obtain a reduced json file includes:

s31, deleting the character data related to the preset field to be deleted in the json file to obtain clean data;

s32, constructing a global unique namespace, and performing name character simplification operation on each variable in the clean data by using the global unique namespace to obtain simplified data;

and S33, identifying the source map file in the simplified data, and deleting the source map file from the simplified data to obtain the simplified json file.

The source mapping file is a json mapping file, and is only used in a project development testing stage, and is not required to be included in an online stage, so that the source mapping file is removed from the json file, and the data volume can be reduced.

Specifically, in the embodiment of the present invention, the simplification policy sets the field to be deleted as a comment and space character string, so that in the embodiment of the present invention, each comment and each space character string in the json file are deleted to obtain clean data, and each variable is simplified as a "variable abcde" to be simplified as a "variable a", wherein, in order to ensure that each simplified variable is a unique variable, in the embodiment of the present invention, each simplified variable is uniformly stored in a global unique namespace and is then placed below the global unique namespace, each simplified variable is recorded by using the global unique namespace, and it is ensured that subsequent simplified variables cannot be reread from the simplified variables, such as the "variable abcde", are simplified as the "variable a", "variable abcdef", and cannot be simplified as the "variable a", but can be simplified into a variable ab, and finally, according to the requirements in the configuration file, the sourceMap file in the json file is deleted to obtain the simplified json file.

S4, according to the simplification strategy, field deletion and character string simplification operations are carried out on each stack style file in the markup language file to obtain a simplified stack style file, and a public style in the simplified stack style file is extracted to obtain a public stack style file.

The Cascading Style Sheets (CSS) file is a file that is referred to by html files by using a preset tag, and includes various general databases, common program packages, and the like. The html file often refers to the CSS style file multiple times or partially, so that the CSS style file has redundancy.

In detail, in the embodiment of the present invention, the extracting a common style from the simplified cascading style file to obtain a common cascading style file includes:

inquiring the style class and the style declaration in the simplified cascading style file to obtain an inquiry result;

and extracting a public style class and a public style declaration from the query result to obtain the public cascading style file.

According to the reduction strategy, like the operations of deleting null values and annotations and the operations of simplifying variables in the S3, the embodiment of the invention simplifies the variables in the CSS style file to obtain the simplified CSS style file.

The method comprises the steps of analyzing the same style class contained in each CSS style file, extracting to obtain a public style class; and analyzing the same style declaration sentences contained in each CSS style file to extract to obtain the common style declaration sentences. And packaging the public style class and the public style declaration statement to generate the public CSS file.

In addition, in another embodiment of the present invention, frame names and library file names in package file directory (package. json) files in the project are obtained, and package file sizes corresponding to the frame names and the library file names are searched from a download management tool package (node _ modules) directory in the project, if the size of a package file corresponding to one frame name or library file name exceeds the threshold, and if 100kb is used, the package file with the package file size larger than 100kb is extracted from the project and stored in a pre-constructed operating server. After the package file with the size larger than 100kb is stored in the server, when the package file with the size larger than the frame and the library file with the size larger than 100kb is required to be used in the software application, the package file with the size larger than the frame and the library file with the size larger than 100kb can be introduced from the running server in an online loading mode, and the data volume in the front-end resource package is further reduced.

S6, according to a preset file starting sequence, sequencing each markup language file and each simplified markup language file, of which the file volume value is smaller than or equal to the simplified threshold value, in the front-end resource package to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public stack style files to obtain a compressed file package of the front-end resource package.

In detail, in the embodiment of the present invention, the sorting, according to a preset file start sequence, each markup language file and each simplified markup language file whose file volume value in the front-end resource package is smaller than or equal to the reduction threshold value to obtain a configuration framework package includes:

summarizing each markup language file and the simplified markup language file of which the file volume value is smaller than or equal to the simplified threshold value in the front-end resource package to obtain a summarized file;

partitioning the summary file by using a pre-constructed combined distribution service according to a preset front-end page content rule to obtain markup language chunks corresponding to each front-end page;

and sequentially arranging all markup language chunks according to a preset file starting sequence to obtain a configuration framework packet corresponding to the front-end resource packet.

Specifically, in the embodiment of the present invention, resource packages corresponding to the html-less files or the html files to be reduced corresponding to the html front-end pages are allocated together to generate an html chunk, and then the public cascading style files corresponding to the html chunk are referred to, so as to obtain a complete page resource package of the front-end page corresponding to the html chunk.

Packaging the configuration framework package, the simplified json file and the public CSS file to obtain a compressed file package of the front-end resource package, wherein the method comprises the following steps:

according to each unique identifier in each simplified markup language file, linking the simplified json file with the configuration framework package to obtain a configuration resource package;

in detail, in the embodiment of the present invention, the packaging the configuration framework package, the simplified json file, and the common CSS file to obtain the compressed file package of the front-end resource package includes:

according to each unique identifier in each simplified markup language file, linking the simplified json file with the configuration framework package to obtain a configuration resource package;

and packaging the configuration resource package and the public stack style file to obtain a compressed file package of the front-end resource package.

And finally, sequencing the page resource packages corresponding to the front end pages according to the file starting sequence to obtain the compressed file packages corresponding to the front end resource packages.

Furthermore, in the embodiment of the present invention, the front-end resource package automatic slimming tool may be constructed through a configuration file config.js, and the pre-constructed front-end resource package automatic slimming tool is started through a preset npmpa-resource-auto-thin-D start command to implement the operation processes from S1 to S6. Js comprises the following configuration files: the html file reduction threshold is 300KB as default, whether a source map file in a json file needs to be deleted, combined sequence intelligent configuration, a frame, a library file online address directory folder address and the like.

Further, in another embodiment of the present invention, after obtaining the compressed file package of the front-end resource package, the method further includes:

encoding the compressed file packet by using a pre-constructed encoder to obtain encoded data;

cutting the coded data according to a preset cutting rule to obtain each coding block;

and storing each coding block into a pre-constructed database server by using a distributed algorithm.

Specifically, in another embodiment of the present invention, the compressed file packet is encoded and block-cut by the pre-established erasure code to obtain each encoding block, and then the hash algorithm is used to perform distributed storage on each encoding block to the data server, so as to increase the storage security of the compressed file packet. The erasure code is a data protection mechanism with a multi-copy mode, and can effectively avoid the situation that original data is damaged due to partial data loss.

The embodiment of the invention takes a markup language file with the file volume larger than a preset compaction threshold value in a front-end resource package as a markup language file to be compacted, obtains the position of each data paragraph of a preset type recorded in the markup language file to be compacted, and marks a preset unique identifier at each position, wherein the unique identifier can link the markup language file and the json file; further, the json file is reduced into the reduced json file according to the reduction strategy, the cascading style file is reduced into the public cascading style file, and the data volume in a front-end resource package is further reduced, so that the product can be normally started under a weak network environment; meanwhile, the invention compresses through a simplification strategy, thereby greatly increasing the compression efficiency. Therefore, the front-end resource package compression method, the front-end resource package compression device, the electronic equipment and the storage medium can improve the compression efficiency of the front-end resource package in the compression process.

Fig. 3 is a functional block diagram of the front-end resource packet compression apparatus according to the present invention.

The front-end resource package compression apparatus 100 of the present invention may be installed in an electronic device. According to the implemented functions, the front-end resource package compressing device may include a markup language file reduction module 101, a json file compression module 102, a common CSS file extraction module 103, and a compressed package generation module 104. A module according to the present invention, which may also be referred to as a unit, refers to a series of computer program segments that can be executed by a processor of an electronic device and that can perform a fixed function, and that are stored in a memory of the electronic device.

In the present embodiment, the functions regarding the respective modules/units are as follows:

the markup language file simplification module 101 is configured to screen a markup language file with a file volume value larger than a preset simplification threshold value from a front-end resource package to obtain a markup language file to be simplified, obtain a preset type of data paragraphs in the markup language file to be simplified, perform one-to-one replacement on each data paragraph by using a preset unique identifier to obtain a simplified markup language file corresponding to the markup language file to be simplified, and store each replaced data paragraph to a pre-constructed json file.

The front-end resource package is a collection of all files installed on the client by a preset software application, and comprises markup language files, json files and the like. In the embodiment of the invention, the Markup Language is HyperText Markup Language (html), the Markup Language file can be read by various web browsers to generate a file for transmitting various information by a web page, and the file is mostly applied to a front-end interface of software application. The json file is a file with a lightweight data exchange format, and the json file is a file with a lightweight data exchange format, is stored and represented in a text format completely independent of a programming language, and is easy to analyze and generate by a machine.

In the embodiment of the invention, the file size of each html file in the front-end resource package is inquired to obtain the volume value of each html file; judging the relation between the volume value of each html file and a preset compaction threshold value; and judging the html file with the volume value less than or equal to the preset compaction threshold value as the html file without compaction, and judging the html file with the volume value greater than the preset compaction threshold value as the html file to be compacted.

Specifically, the html file in the front-end resource package may contain character strings in the order of ten thousand, such as various types of texts like "user protocols", and the html file containing the text has a large text volume, which is usually larger than the preset reduction threshold, wherein the reduction threshold is set to 300KB in the embodiment of the present invention.

In the embodiment of the invention, all html files in the front-end resource package are screened, and the html file with the volume value larger than 300KB is defined as the html file to be reduced. According to the embodiment of the invention, the volume value of the html file to be reduced can be reduced by reducing the html file to be reduced, so that a large amount of data does not need to be loaded when the software application is started for the first time, and the starting time is shortened.

Furthermore, in the embodiment of the invention, the automatic slimming tool of the front-end resource package is constructed through the configuration file config. And starting the operation process of the pre-constructed front-end resource package automatic slimming tool through a preset npmpas-resource-auto-thin-D starting command. Js includes: the html file reduction threshold is 300KB as default, whether a source map file in a json file needs to be deleted, combined sequence intelligent configuration, a frame, a library file online address directory folder address and the like.

In the embodiment of the invention, the category monitoring of all html files in the front-end resource package is realized through a pre-constructed monitoring service, and when the html files are html files which do not need to be simplified, processing is not needed; when the html file is the html file to be reduced, opening the html file to be reduced, extracting data paragraphs such as text paragraphs, videos and pictures in the closed labels according to the closed labels in the html file to be reduced, marking a globally unique identifier at a position where the data paragraphs are stored in the closed labels, and obtaining the reduced html file.

In detail, in the embodiment of the present invention, when the markup language file reduction module 101 stores each replaced data segment in a pre-constructed json file, the markup language file reduction module is specifically configured to:

creating a json file by using a pre-constructed scene collaborative service, and naming the json file by using the file name of the markup language file to be simplified;

and constructing a hierarchy corresponding to the unique identifier in the json file according to the unique identifier, and saving each data paragraph to be below the hierarchy corresponding to the unique identifier.

In the embodiment of the invention, a json file is constructed, the json file is named as the same name as the html file to be simplified, and after the naming is finished, the unique identifier and the corresponding data paragraph are stored in the json file in a one-to-one correspondence manner.

The simplified html file and the json file both have corresponding unique identifiers, and the link between the simplified html file and the simplified json file can be established according to the unique identifiers. When the software application is started, each simplified html file is executed firstly, and only when a client queries detailed data, such as protocol content and the like, the unique identifier in the simplified html file is triggered to call the json file for loading.

The json file compression module 102 is configured to perform field deletion and character string reduction on the json file according to a preset reduction policy, so as to obtain a reduced json file.

Js is a simplified process execution policy pre-configured in the configuration file config, for example, a variable is converted, abbreviated, deleted, and the like.

In detail, in the embodiment of the present invention, when the json file compression module 102 performs field deletion and character string reduction on the json file according to a preset reduction policy to obtain a reduced json file, the json file compression module is specifically configured to:

deleting character data related to a preset field to be deleted in the json file to obtain clean data;

constructing a global unique naming space, and carrying out name character simplification operation on each variable in the clean data by using the global unique naming space to obtain simplified data;

and identifying a source mapping file in the simplified data, and deleting the source mapping file from the simplified data to obtain the simplified json file.

The source mapping file is a json mapping file, and is only used in a project development testing stage, and is not required to be included in an online stage, so that the source mapping file is removed from the json file, and the data volume can be reduced.

Specifically, in the embodiment of the present invention, the simplification policy sets the field to be deleted as a comment and space character string, so that in the embodiment of the present invention, each comment and each space character string in the json file are deleted to obtain clean data, and each variable is simplified as a "variable abcde" to be simplified as a "variable a", wherein, in order to ensure that each simplified variable is a unique variable, in the embodiment of the present invention, each simplified variable is uniformly stored in a global unique namespace and is then placed below the global unique namespace, each simplified variable is recorded by using the global unique namespace, and it is ensured that subsequent simplified variables cannot be reread from the simplified variables, such as the "variable abcde", are simplified as the "variable a", "variable abcdef", and cannot be simplified as the "variable a", but can be simplified into a variable ab, and finally, according to the requirements in the configuration file, the sourceMap file in the json file is deleted to obtain the simplified json file.

The common CSS file extraction module 103 performs field deletion and character string reduction operations on each stack style file in the markup language file according to the reduction policy to obtain a simplified stack style file, and extracts a common style in the simplified stack style file to obtain a common stack style file.

The CSS style file is a file which is referred by an html file by using a preset label, and comprises various general databases, common program packages and the like. The html file often refers to the CSS style file multiple times or partially, so that the CSS style file has redundancy.

In detail, in the embodiment of the present invention, when the common cascading style file extracting module 103 extracts the common style in the simplified cascading style file to obtain the common cascading style file, it is specifically configured to:

inquiring the style class and the style declaration in the simplified cascading style file to obtain an inquiry result;

and extracting a public style class and a public style declaration from the query result to obtain the public cascading style file.

According to the simplification strategy, like the operation of deleting null values and comments and the operation of simplifying variables in the json file compression module 102, the embodiment of the invention simplifies the variables in the cascading style file to obtain the simplified cascading style file.

The method comprises the steps of analyzing the same style class contained in each CSS style file, extracting to obtain a public style class; and analyzing the same style declaration sentences contained in each CSS style file to extract to obtain the common style declaration sentences. And packaging the public style class and the public style declaration statement to generate the public CSS file.

In addition, in another embodiment of the present invention, frame names and library file names in package file directory (package. json) files in the project are obtained, and package file sizes corresponding to the frame names and the library file names are searched from a download management tool package (node _ modules) directory in the project, if the size of a package file corresponding to one frame name or library file name exceeds the threshold, and if 100kb is used, the package file with the package file size larger than 100kb is extracted from the project and stored in a pre-constructed operating server. After the package file with the size larger than 100kb is stored in the server, when the package file with the size larger than the frame and the library file with the size larger than 100kb is required to be used in the software application, the package file with the size larger than the frame and the library file with the size larger than 100kb can be introduced from the running server in an online loading mode, and the data volume in the front-end resource package is further reduced.

The compressed package generating module 104 is configured to sequence, according to a preset file starting sequence, each markup language file and each simplified markup language file, of which the file volume value in the front-end resource package is smaller than or equal to the reduction threshold, to obtain a configuration frame package, and package the configuration frame package, the simplified json files, and the common cascading style files to obtain a compressed file package of the front-end resource package.

In detail, in this embodiment of the present invention, when the compressed packet generation module 104 sequences, according to a preset file start sequence, each markup language file and each simplified markup language file whose file volume value in the front-end resource packet is less than or equal to the reduction threshold, to obtain a configuration framework packet, specifically configured to:

summarizing each markup language file and the simplified markup language file of which the file volume value is smaller than or equal to the simplified threshold value in the front-end resource package to obtain a summarized file;

partitioning the summary file by using a pre-constructed combined distribution service according to a preset front-end page content rule to obtain markup language chunks corresponding to each front-end page;

and sequentially arranging all markup language chunks according to a preset file starting sequence to obtain a configuration framework packet corresponding to the front-end resource packet.

Specifically, in the embodiment of the present invention, resource packages corresponding to the html-less files or the html files to be reduced corresponding to the html front-end pages are allocated together to generate an html chunk, and then the public cascading style files corresponding to the html chunk are referred to, so as to obtain a complete page resource package of the front-end page corresponding to the html chunk.

Packaging the configuration frame package, the simplified json file and the public cascading style file to obtain a compressed file package of the front-end resource package, wherein the method comprises the following steps:

according to each unique identifier in each simplified markup language file, linking the simplified json file with the configuration framework package to obtain a configuration resource package;

in detail, in the embodiment of the present invention, when the compressed package generation module 104 packages the configuration frame package, the simplified json file, and the common cascading style file to obtain the compressed file package of the front-end resource package, specifically:

according to each unique identifier in each simplified markup language file, linking the simplified json file with the configuration framework package to obtain a configuration resource package;

and packaging the configuration resource package and the public stack style file to obtain a compressed file package of the front-end resource package.

And finally, sequencing the page resource packages corresponding to the front end pages according to the file starting sequence to obtain the compressed file packages corresponding to the front end resource packages.

Furthermore, in the embodiment of the present invention, an automatic slimming tool of a front-end resource package may be constructed through the configuration file config.js, and an operation process of a pre-constructed automatic slimming device of the front-end resource package may be started through a preset npmpa-resource-auto-thin-D start command. Js comprises the following configuration files: the html file reduction threshold is 300KB as default, whether a source map file in a json file needs to be deleted, combined sequence intelligent configuration, a frame, a library file online address directory folder address and the like.

Further, in another embodiment of the present invention, after obtaining the compressed file package of the front-end resource package, the compressed package generating module 104 is further configured to:

encoding the compressed file packet by using a pre-constructed encoder to obtain encoded data;

cutting the coded data according to a preset cutting rule to obtain each coding block;

and storing each coding block into a pre-constructed database server by using a distributed algorithm.

Specifically, in another embodiment of the present invention, the compressed file packet is encoded and block-cut by the pre-established erasure code to obtain each encoding block, and then the hash algorithm is used to perform distributed storage on each encoding block to the data server, so as to increase the storage security of the compressed file packet. The erasure code is a data protection mechanism with a multi-copy mode, and can effectively avoid the situation that original data is damaged due to partial data loss.

Fig. 4 is a schematic structural diagram of an electronic device implementing the front-end resource packet compression method according to the present invention.

The electronic device may comprise a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may further comprise a computer program, such as a front-end resource packet compression program, stored in the memory 11 and executable on the processor 10.

In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same function or different functions, and includes one or more Central Processing Units (CPUs), a microprocessor, a digital Processing chip, a graphics processor, a combination of various control chips, and the like. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device by running or executing programs or modules (for example, executing a front-end resource package compression program) stored in the memory 11 and calling data stored in the memory 11.

The memory 11 includes at least one type of readable storage medium including flash memory, removable hard disks, multimedia cards, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disks, optical disks, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device, for example a removable hard disk of the electronic device. The memory 11 may also be an external storage device of the electronic device in other embodiments, such as a plug-in mobile 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 electronic device. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device. The memory 11 may be used to store not only application software installed in the electronic device and various types of data, such as codes of a front-end resource package compression program, but also temporarily store data that has been output or is to be output.

The communication bus 12 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like.

The communication interface 13 is used for communication between the electronic device and other devices, and includes a network interface and a user interface. Optionally, the network interface may include a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), which are typically used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a Display (Display), an input unit such as a Keyboard (Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the electronic device and for displaying a visualized user interface.

Fig. 4 shows only an electronic device having components, and those skilled in the art will appreciate that the structure shown in fig. 4 does not constitute a limitation of the electronic device, and may include fewer or more components than those shown, or some components may be combined, or a different arrangement of components.

For example, although not shown, the electronic device may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so that functions of charge management, discharge management, power consumption management and the like are realized through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.

It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.

The front-end resource package compression program stored in the memory 11 of the electronic device is a combination of a plurality of computer programs, and when running in the processor 10, can realize:

screening markup language files with file volume values larger than a preset compaction threshold value from a front-end resource package to obtain markup language files to be compacted;

acquiring data paragraphs of preset types in the markup language file to be simplified, performing one-to-one replacement on each data paragraph by using a preset unique identifier to obtain a simplified markup language file corresponding to the markup language file to be simplified, and storing each replaced data paragraph into a pre-constructed json file;

according to a preset simplification strategy, field deletion and character string simplification operations are carried out on the json file to obtain a simplified json file;

according to the simplification strategy, field deletion and character string simplification operations are carried out on each cascading style file in the markup language file to obtain a simplified cascading style file, and a public style in the simplified cascading style file is extracted to obtain a public cascading style file;

sequencing each markup language file with a file volume value smaller than or equal to the simplified threshold value and each simplified markup language file in the front-end resource package according to a preset file starting sequence to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public cascading style files to obtain a compressed file package of the front-end resource package.

Specifically, the specific implementation method of the instruction by the processor 10 may refer to the description of the relevant steps in the embodiment corresponding to the drawings, which is not described herein again.

Further, the electronic device integrated module/unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a non-volatile computer-readable storage medium. The computer readable storage medium may be volatile or non-volatile. For example, the computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).

The present invention also provides a computer-readable storage medium, storing a computer program which, when executed by a processor of an electronic device, may implement:

screening markup language files with file volume values larger than a preset compaction threshold value from a front-end resource package to obtain markup language files to be compacted;

acquiring data paragraphs of preset types in the markup language file to be simplified, performing one-to-one replacement on each data paragraph by using a preset unique identifier to obtain a simplified markup language file corresponding to the markup language file to be simplified, and storing each replaced data paragraph into a pre-constructed json file;

according to a preset simplification strategy, field deletion and character string simplification operations are carried out on the json file to obtain a simplified json file;

according to the simplification strategy, field deletion and character string simplification operations are carried out on each cascading style file in the markup language file to obtain a simplified cascading style file, and a public style in the simplified cascading style file is extracted to obtain a public cascading style file;

sequencing each markup language file with a file volume value smaller than or equal to the simplified threshold value and each simplified markup language file in the front-end resource package according to a preset file starting sequence to obtain a configuration frame package, and packaging the configuration frame package, the simplified json files and the public cascading style files to obtain a compressed file package of the front-end resource package.

In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.

The modules described as separate parts may or may not be physically separate, and parts displayed as modules 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 modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.

In addition, functional modules 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, or in a form of hardware plus a software functional module.

It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.

The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.

The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.

Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.

Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

20页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种以差分序列为基础的自动气象站自动集群方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!