Resource cleaning method and device, electronic equipment and storage medium
By analyzing and comparing the information list of static resources in front-end projects, identifying and deleting uncited static resources, the problems of poor loading performance and high maintenance costs caused by static resource redundancy are solved, and more efficient resource management and loading process optimization are achieved.
Patent Information
- Application Number
- CN202411998667.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-23
AI Technical Summary
During front-end development, static resource redundancy leads to poor project loading performance and high maintenance costs, making it difficult for existing tools to effectively identify and clean up uncited static resources.
By obtaining the relevant information list of static resources in the project, parse the static resources referenced in the output file, compare the differences between the two, generate an information list of unreferenced static resources, and delete these resources.
Improve the accuracy of static resource monitoring, ensure the accuracy of resource cleaning, optimize the project loading process, and reduce maintenance costs.
Smart Images

Figure CN120029618A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of software development technology, and in particular, relates to a resource cleaning method, device, electronic device and storage medium. Background Art
[0002] In the process of front-end development, projects often need to introduce a large number of static resources, such as images and videos. However, with the iteration of the project, the static resources introduced in the past will no longer be referenced, resulting in redundancy. Unreferenced static resources will increase the file size of the project package, thereby affecting the loading performance and maintenance cost of the project.
[0003] Therefore, a method for cleaning up static resources is urgently needed. Summary of the invention
[0004] The purpose of this application is to provide a resource cleaning method, device, electronic device and storage medium, aiming to solve the problems of difficult project loading and high maintenance costs caused by static resource redundancy in the traditional front-end development process.
[0005] A first aspect of an embodiment of the present application provides a resource cleaning method, the method comprising:
[0006] Obtain a first information list of static resources in the project to be cleaned up, wherein the first information list includes relevant information of the static resources in the project;
[0007] Extracting relevant information of the static resources in the output file based on the file format of the static resources referenced in the output file to obtain a second information list, wherein the output file is an output file generated after the project is packaged;
[0008] Comparing the first information list with the second information list to obtain a third information list, wherein the third information list includes relevant information of unused static resources in the output file;
[0009] The static resources in the third information list are deleted from the resources of the project.
[0010] In some embodiments, extracting relevant information of the static resources in the output file based on the file format of the static resources referenced in the output file to obtain the second information list includes:
[0011] Parse the output file to obtain a first static resource in a web page format and a second static resource in an audio and video format in the output file;
[0012] Parsing the first static resource to obtain a third static resource in an audio and video format and a fourth static resource in another format from the static resource in the webpage format;
[0013] The second information list is generated based on the relevant information of the second static resource, the third static resource and the fourth static resource.
[0014] In some embodiments, generating the second information list based on the relevant information of the second static resource, the third static resource and the fourth static resource includes:
[0015] Determine a coded static resource from the second static resource and the third static resource;
[0016] Decoding the encoded static resource in the second static resource and the third static resource to obtain the corresponding second static resource in a non-encoded format and the third static resource in a non-encoded format;
[0017] Querying the relevant information corresponding to the second static resource in non-coding format, the third static resource in non-coding format, and the fourth static resource from the project file of the project to be cleaned up;
[0018] The second information list is composed of the related information corresponding to the second static resource in non-coding format, the third static resource in non-coding format and the fourth static resource.
[0019] In some embodiments, after comparing the first information list and the second information list to obtain a third information list, the method further includes:
[0020] Generate prompt information based on the third information list, the prompt information is used to prompt the user to delete the static resources corresponding to the third information list;
[0021] The prompt information is output.
[0022] In some embodiments, deleting the static resources in the third information list from the resources of the project includes:
[0023] In response to a confirmation operation based on the prompt information, the static resources in the third information list are deleted from the resources of the project.
[0024] In some embodiments, deleting the static resources in the third information list from the resources of the project includes:
[0025] Call resource cleanup function;
[0026] Based on the resource clearing function, the static resources in the third information list are deleted from the resources of the project.
[0027] In some embodiments, the obtaining of a first information list of static resources in the project to be cleared includes relevant information of the static resources in the project, including:
[0028] Get the project directory of the project to be cleaned up;
[0029] Traverse the project files of the project based on the project directory to obtain relevant information of static resources in the project;
[0030] The first information list is generated based on the relevant information of the static resources in the project.
[0031] A second aspect of an embodiment of the present application provides a resource cleaning device, the device comprising:
[0032] An acquiring unit, configured to acquire a first information list of static resources in a project to be cleaned up, wherein the first information list includes relevant information of the static resources in the project;
[0033] An extraction unit, configured to extract relevant information of static resources in an output file based on a file format of static resources referenced in the output file to obtain a second information list, wherein the output file is an output file generated after the project is packaged;
[0034] a comparing unit, configured to compare the first information list with the second information list to obtain a third information list, wherein the third information list includes relevant information of unused static resources in the output file;
[0035] A clearing unit is used to delete the static resources in the third information list from the resources of the project.
[0036] In some embodiments, the extraction unit is used to parse the output file to obtain a first static resource in a web page format and a second static resource in an audio and video format in the output file; parse the first static resource to obtain a third static resource in an audio and video format and a fourth static resource in other formats in the static resources in the web page format; and generate the second information list based on relevant information of the second static resource, the third static resource and the fourth static resource.
[0037] In some embodiments, the extraction unit is used to determine the encoded static resource from the second static resource and the third static resource; decode the encoded static resource in the second static resource and the third static resource to obtain the corresponding second static resource in non-encoded format and the third static resource in non-encoded format; query the relevant information corresponding to the second static resource in non-encoded format, the third static resource in non-encoded format and the fourth static resource from the project file of the project to be cleaned up; and form the second information list with the relevant information corresponding to the second static resource in non-encoded format, the third static resource in non-encoded format and the fourth static resource.
[0038] In some embodiments, the apparatus further comprises:
[0039] A generating unit, configured to generate prompt information based on the third information list, wherein the prompt information is used to prompt a user to delete the static resources corresponding to the third information list;
[0040] An output unit is used to output the prompt information.
[0041] In some embodiments, the clearing unit is used to delete the static resources in the third information list from the resources of the project in response to a confirmation operation based on the prompt information.
[0042] In some embodiments, the clearing unit is used to call a resource clearing function; based on the resource clearing function, the static resources in the third information list are deleted from the resources of the project.
[0043] In some embodiments, the acquisition unit is used to obtain the project directory of the project to be cleaned; traverse the project files of the project based on the project directory to obtain relevant information of static resources in the project; and generate the first information list based on the relevant information of static resources in the project.
[0044] A third aspect of an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the resource cleaning method described above when executing the computer program.
[0045] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the resource cleaning method described above is implemented.
[0046] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0047] In an embodiment of the present application, by traversing the static resources in the project to be cleaned up, a first information list containing relevant information of all static resources in the static project is obtained, and the output file after the project is packaged is parsed, and based on the file format of the static resources obtained by the parsing, relevant information of the static resources referenced by the output file is extracted from the output file to obtain a second information list, and by comparing the first information list and the second information list, a third information list of static resources not referenced in the project is obtained, and then the static resources in the third information list are deleted, so that the static resources referenced in the output file are determined by the file format of the static resources referenced in the output file, thereby preventing the unreferenced static resources from being missed, improving the accuracy of static resource monitoring, and then improving the accuracy of unreferenced resources in the cleaned project, optimizing the project loading process, and reducing maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 A schematic diagram of a front-end tool for resource cleanup provided by an exemplary embodiment is shown;
[0049] Figure 2 A schematic diagram showing a flow chart of a resource cleaning method provided by an exemplary embodiment;
[0050] Figure 3 A schematic diagram showing a flow chart of a resource cleaning method provided by an exemplary embodiment;
[0051] Figure 4 A schematic diagram showing a flow chart of a resource cleaning method provided by an exemplary embodiment;
[0052] Figure 5 A schematic diagram of the structure of a resource cleaning device provided by an exemplary embodiment is shown;
[0053] Figure 6 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0054] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0055] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0056] In the process of front-end development, project development often requires the introduction of a large number of static resources, such as images and videos. However, in the process of project use, it is often necessary to iterate and update the project. With the iterative update of the project, new static resources will be introduced, and the static resources introduced in the past will no longer be referenced, resulting in resource redundancy. This results in a large size of project files, which is not conducive to project loading and increases the maintenance cost of the project.
[0057] At present, a variety of front-end tools are set up to maintain front-end projects. However, the existing tools have limited detection of unreferenced static resources and cannot effectively identify and clean up unreferenced resources, which causes the project size to expand and brings inconvenience to development and maintenance.
[0058] The present application provides a front-end tool for resource cleaning, which can effectively identify unreferenced static resources and delete unreferenced static resources from project files, thereby effectively maintaining the size of project files, ensuring smooth project loading, and reducing project maintenance costs.
[0059] The solution of the present application is described below in conjunction with specific embodiments. Figure 1 , which shows a schematic diagram of a processing module included in a front-end tool for resource cleanup provided by an exemplary embodiment. Figure 1 ,The front-end tool includes a static resource collection module, a packaged output file parsing module, an unreferenced resource identification module and a resource deletion module.
[0060] The static resource collection module is used to collect all static resources of the project, including pictures, videos, audio and other resources. All static resources in the project are determined by traversing the static resource files in the entire project directory, and a first information list containing relevant information of all static resources is generated.
[0061] The packaged output file parsing module is used to parse the output file after the project is packaged, extract the reference information of the static resources in the output file, determine that all the applied resources in the output file can be identified, and generate a second information list containing relevant information of all referenced resources.
[0062] The unreferenced resource identification module is used to identify static resources that are not referenced by the output file by comparing the first information list with the second information list, and to generate a third information list based on the relevant information of the unused resources.
[0063] The resource deletion module is used to delete unreferenced static resources in the project based on the third information list.
[0064] In some embodiments, the front-end tool also includes a resource encoding module for encoding smaller static resources in the project or decoding smaller static resources in the output file, so that the comparison can be performed in the same format during the comparison process to prevent static resources from being accidentally deleted.
[0065] The resource cleaning method provided by this application is described below in conjunction with specific embodiments. Figure 2 , which shows a schematic flow chart of a resource cleaning method provided by an exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device, and the electronic device is provided with the above-mentioned front-end tool.
[0066] S201, the electronic device obtains a first information list of static resources in a project to be cleared, where the first information list includes relevant information of the static resources in the project.
[0067] In this step, the electronic device obtains the project directory of the project to be cleaned, and traverses the project files storing static resources under the project based on the resource directory. The project directory can be any type of project directory. For example, the project directory can be a src / assets directory, etc. Accordingly, the electronic device obtains the project directory of the project to be cleaned; traverses the project files of the project based on the project directory to obtain relevant information of static resources in the project; and generates the first information list based on the relevant information of static resources in the project.
[0068] The project file stores all the main resources for executing the project, such as source code, project configuration files and other related resources, among which the static resources of the project file are generally stored under the source code. Correspondingly, the corresponding project directory is src / assets. The electronic device determines the storage path of the static resources based on the project directory, traverses the folders storing static resources in the project file based on the storage path of the static resources, obtains the relevant information of the static resources of the project from the folder, and composes the relevant information into the first information list.
[0069] The relevant information of the static resource may be any information used to uniquely identify the static resource. For example, the relevant information of the static resource may be the storage path of the static resource in the project file, resource identification, and other information.
[0070] In some embodiments, the electronic device can use the glob library to collect all static resources of a specified type under the project directory, and store the traversed static resources of the specified type in the first information list. Among them, the project directory and the specified type can be set as needed. In the embodiment of the present application, the project directory and the specified type are not specifically limited. For example, the project directory is set to the src directory, and the specified type can be a resource type such as .png, .jpg, .jpeg, .gif, .svg or .mp4.
[0071] S202, the electronic device extracts relevant information of the static resources in the output file based on the file format of the static resources referenced in the output file to obtain a second information list, and the output file is an output file generated after the project is packaged.
[0072] The types of static resources include many, for example, pictures, videos, fonts and style files, etc. These files play different roles in the project. When packaging project files, static resources need to be packaged into different formats according to their different roles. For example, for static resources used to generate page files, the static resources can be packaged into a web page format, such as a file in .html format. For static resources with other functions, the static resources can be packaged according to the type of static resources, such as packaging video files into files in .js format, packaging smaller picture codes into files in .css format, etc.
[0073] Accordingly, in this step, the output file is parsed, the corresponding static resource file is obtained from the parsed file, the static resource file is determined as a referenced file, and a second information list is generated based on relevant information of the referenced file.
[0074] S203: The electronic device compares the first information list with the second information list to obtain a third information list, where the third information list includes relevant information of unused static resources in the output file.
[0075] In this step, the electronic device matches the relevant information in the first information list with the information in the second information list respectively. For the relevant information of any static resource in the first information list, if there is relevant information in the second information list that matches the relevant information of the static resource, the relevant information will not be recorded in the third information list. If there is no relevant information in the second information list that matches the relevant information of the static resource, the relevant information will be recorded in the third information list. In this way, the relevant information in the first information list is compared with the relevant information in the second information list respectively, and the relevant information in the first information list that does not match the relevant information in the second information list forms the third information list.
[0076] S204: The electronic device deletes the static resources in the third information list from the resources of the project.
[0077] The electronic device can traverse the static resources in the project file based on the relevant information in the third information list, and delete the traversed static resources.
[0078] In some embodiments, a delete option is configured in the front-end tool of the electronic device. Accordingly, the electronic device can directly traverse the project file based on the third information list when obtaining the third information list, and perform a delete operation on the corresponding static resources in the third information list.
[0079] Among them, the electronic device can directly delete the corresponding static resources in the third information list. Alternatively, the electronic device can generate prompt information, and only perform the operation of deleting the corresponding static resources in the third information list after receiving a confirmation operation based on the prompt information. Accordingly, the electronic device generates prompt information based on the third information list, and the prompt information is used to prompt the user to delete the static resources corresponding to the third information list; and outputs the prompt information. In response to the confirmation operation based on the prompt information, the electronic device deletes the static resources in the third information list from the resources of the project.
[0080] In this implementation, prompt information is output to confirm with the user whether it is necessary to delete the unreferenced static resources, thereby preventing the static resources from being deleted accidentally.
[0081] It should be noted that the confirmation operation can be to confirm the deletion of all static resources in the static resources corresponding to the third information list. In some embodiments, the user can also output a selection operation, select the relevant information of the static resources that he wants to delete from the output prompt information, and then the electronic device deletes the selected static resources based on the confirmation operation.
[0082] In other embodiments, the front-end tool of the electronic device is not configured with a deletion option. Accordingly, the electronic device can generate a report file based on the third relevant information and output the report file. The report file includes relevant information about static resources that are not used in the project. The user can view the report file through the electronic device, and the user can determine whether to delete the corresponding resources based on the report file. Accordingly, the user can manually delete the corresponding static resources.
[0083] The electronic device may call a pre-configured resource clearing function to delete the static resources in the third information list. Accordingly, the electronic device calls the resource clearing function; based on the resource clearing function, the static resources in the third information list are deleted from the resources of the item.
[0084] In an embodiment of the present application, by traversing the static resources in the project to be cleaned up, a first information list containing relevant information of all static resources in the static project is obtained, and the output file after the project is packaged is parsed, and based on the file format of the static resources obtained by the parsing, relevant information of the static resources referenced by the output file is extracted from the output file to obtain a second information list, and by comparing the first information list and the second information list, a third information list of static resources not referenced in the project is obtained, and then the static resources in the third information list are deleted, so that the static resources referenced in the output file are determined by the file format of the static resources referenced in the output file, thereby preventing the unreferenced static resources from being missed, improving the accuracy of static resource monitoring, and then improving the accuracy of unreferenced resources in the cleaned project, optimizing the project loading process, and reducing maintenance costs.
[0085] In practical applications, when extracting static resources from an output file, it is often not convenient to obtain smaller files. In the embodiment of the present application, the static resources in the output file are determined by the file format of the static resources in the output file, which further prevents the static resource files in the output file from being missed, thereby preventing accidental deletion. Accordingly, the above step S202 can be further implemented by the following steps S302-SS304, see Figure 3 , which shows a schematic flow chart of a resource cleaning method provided by an exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device, and the electronic device is provided with the above-mentioned front-end tool.
[0086] S301, the electronic device obtains a first information list of static resources in a project to be cleared, where the first information list includes relevant information of the static resources in the project.
[0087] The principle of this step is the same as that of step S201 and will not be repeated here.
[0088] S302: The electronic device parses the output file to obtain a first static resource in a web page format and a second static resource in an audio or video format in the output file.
[0089] The electronic device parses the output file, obtains the format information of all resources in the output file, and searches for the format information representing the static resources from the parsed file, for example, searching for static resources in the formats of .js, .html, or .css. Based on the format information of all static resources in the output file, the static resources in the output file are classified, and the static resources whose file format represents the web page format are determined as the first static resources, and the static resources in other formats are determined as the second static resources. In the embodiment of the present application, the static resources in other formats are used as static resources in audio and video formats.
[0090] In some embodiments, the electronic device parses all files in the target of the constructed output file, stores the parsed static resource files in a target list, for example, in an "outputFiles" list, and then traverses the target list to determine the format information of each static resource.
[0091] S303: The electronic device parses the first static resource to obtain a third static resource in an audio or video format and a fourth static resource in another format from the static resource in the webpage format.
[0092] Since the web page formatted static resource stores multiple static resources referenced by the project in the web page formatted file, it is necessary to further parse the first static resource in the web page formatted. The electronic device can parse the first static resource using any parsing method as needed. For example, the electronic device can use the node-html-parser function to parse the first static resource.
[0093] See also Figure 4 , which shows a flow chart of a resource cleaning method provided in an embodiment of the present application. By parsing the first static resource, extract the static resource whose file name indicates that the static resource is in an audio and video format in the first static resource, for example, extract the static resource whose file name is img and video source in the first static resource. In some embodiments, the electronic device may only extract relevant information of the third static resource in an audio and video format in the first static resource, such as path information, etc., which is not specifically limited in the embodiment of the present application.
[0094] After the electronic device obtains the third static resource in the audio and video format by parsing the first static resource, the electronic device determines other static resources in the first static resource as the fourth static resource.
[0095] S304: The electronic device generates the second information list based on the relevant information of the second static resource, the third static resource and the fourth static resource.
[0096] In some embodiments, the electronic device compares the relevant information of the second static resources, the third static resources, and the fourth static resources with the relevant information of the static resources in the first information list, and determines the relevant information of the static resources among the second static resources, the third static resources, and the fourth static resources that matches the relevant information of the static resources in the first information list as the second information list.
[0097] Since the second static resource and the third static resource are static resources corresponding to the audio and video files, which contain small image resources, and for the small image resources, it is necessary to use a preset encoding method to encode the static resources when packaging the output file, therefore, in this step, the resources can be encoded and then compared. Accordingly, the process can be implemented by the following steps S3041-S3044, including:
[0098] S3041, the electronic device determines a coded static resource from the second static resource and the third static resource.
[0099] When packaging the project to obtain the output file, for smaller static resources in the project, it is necessary to encode the static resources according to a preset encoding method. Accordingly, in this step, the encoded static resources obtained after encoding are checked from the second static resource and the third static resource.
[0100] The preset encoding method can be any type of encoding method, for example, encoding using a base64 encoder or encoding using a hash value. Accordingly, the electronic device queries the static resource corresponding to the corresponding encoding method according to the preset encoding method. For example, if the base64 encoder is used for encoding, the electronic device queries the static resource in the base64 encoding format from the second static resource and the third static resource.
[0101] S3042: The electronic device decodes the encoded static resource in the second static resource and the third static resource to obtain the corresponding second static resource in a non-encoded format and the third static resource in a non-encoded format.
[0102] The electronic device decodes the encoded static resources in the second static resource and the third static resource based on a decoding method corresponding to a preset encoding method. For example, if a base64 encoder is used for encoding, the electronic device decodes the encoded static resources in the second static resource and the third static resource using a base64 decoder to obtain the corresponding second static resource in a non-encoded format and the third static resource in a non-encoded format.
[0103] S3043, the electronic device queries the project file of the project to be cleared for relevant information corresponding to the second static resource in a non-coding format, the third static resource in a non-coding format, and the fourth static resource.
[0104] The electronic device can identify the static resource in the project file by the file names of the second static resource in a non-encoded format, the third static resource in a non-encoded format, and the fourth static resource.
[0105] S3044: The electronic device combines the related information corresponding to the second static resource in a non-coded format, the third static resource in a non-coded format, and the fourth static resource into a second information list.
[0106] The electronic device assembles the second information list with the relevant information of the static resource whose file name is found in the line item file.
[0107] In this implementation, the electronic device queries the encoded static resources in the output file, restores the resource format of the encoded static resources by decoding, and then queries the relevant static resources from the project file of the project to prevent the encoded static resources from being unable to be queried from the project file, resulting in the encoded static resources being mistakenly identified as unreferenced resources, thereby preventing the static resources from being accidentally deleted and improving the accuracy of resource cleaning.
[0108] One point that needs to be explained is that the electronic device can also encode the static resources in the project file according to a preset encoding method, and then the electronic device queries the relevant information corresponding to the fourth static resource from the static resources of the project to be cleaned, and queries the second static resource in non-encoded format and the third static resource in non-encoded format from the static resources of the encoded project, and then the relevant information of the queried static resources is combined into a second information list.
[0109] S305: The electronic device deletes the static resources in the third information list from the resources of the project.
[0110] The principle of this step is the same as that of step S204 and will not be repeated here.
[0111] In an embodiment of the present application, by traversing the static resources in the project to be cleaned up, a first information list containing relevant information of all static resources in the static project is obtained, and the output file after the project is packaged is parsed, and based on the file format of the static resources obtained by the parsing, relevant information of the static resources referenced by the output file is extracted from the output file to obtain a second information list, and by comparing the first information list and the second information list, a third information list of static resources not referenced in the project is obtained, and then the static resources in the third information list are deleted, so that the static resources referenced in the output file are determined by the file format of the static resources referenced in the output file, thereby preventing the unreferenced static resources from being missed, improving the accuracy of static resource monitoring, and then improving the accuracy of unreferenced resources in the cleaned project, optimizing the project loading process, and reducing maintenance costs.
[0112] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0113] See also Figure 5 , which shows a schematic diagram of the structure of a resource cleaning device provided by the present application, including various units for executing various steps in the above embodiments, see Figure 5 , the resource cleaning device comprises:
[0114] An acquisition unit 501 is used to acquire a first information list of static resources in a project to be cleared, where the first information list includes relevant information of the static resources in the project;
[0115] An extraction unit 502 is used to extract relevant information of static resources in the output file based on the file format of the static resources referenced in the output file to obtain a second information list, and the output file is an output file generated after the project is packaged;
[0116] A comparing unit 503 is used to compare the first information list with the second information list to obtain a third information list, where the third information list includes relevant information of unused static resources in the output file;
[0117] The clearing unit 504 is used to delete the static resources in the third information list from the resources of the project.
[0118] In some embodiments, the extraction unit 502 is used to parse the output file to obtain a first static resource in a web page format and a second static resource in an audio and video format in the output file; parse the first static resource to obtain a third static resource in an audio and video format and a fourth static resource in other formats in the static resources in the web page format; and generate the second information list based on relevant information of the second static resource, the third static resource and the fourth static resource.
[0119] In some embodiments, the extraction unit 502 is used to determine the encoded static resource from the second static resource and the third static resource; decode the encoded static resource in the second static resource and the third static resource to obtain the corresponding second static resource in non-encoded format and the third static resource in non-encoded format; query the relevant information corresponding to the second static resource in non-encoded format, the third static resource in non-encoded format and the fourth static resource from the project file of the project to be cleaned; and form the second information list with the relevant information corresponding to the second static resource in non-encoded format, the third static resource in non-encoded format and the fourth static resource.
[0120] In some embodiments, the apparatus further comprises:
[0121] A generating unit, configured to generate prompt information based on the third information list, wherein the prompt information is used to prompt a user to delete the static resource corresponding to the third information list;
[0122] The output unit is used to output the prompt information.
[0123] In some embodiments, the clearing unit 504 is used to delete the static resources in the third information list from the resources of the project in response to a confirmation operation based on the prompt information.
[0124] In some embodiments, the clearing unit 504 is used to call a resource clearing function; based on the resource clearing function, the static resources in the third information list are deleted from the resources of the project.
[0125] In some embodiments, the acquisition unit 501 is used to obtain the project directory of the project to be cleaned; traverse the project files of the project based on the project directory to obtain relevant information of static resources in the project; and generate the first information list based on the relevant information of static resources in the project.
[0126] In an embodiment of the present application, by traversing the static resources in the project to be cleaned up, a first information list containing relevant information of all static resources in the static project is obtained, and the output file after the project is packaged is parsed, and based on the file format of the static resources obtained by the parsing, relevant information of the static resources referenced by the output file is extracted from the output file to obtain a second information list, and by comparing the first information list and the second information list, a third information list of static resources not referenced in the project is obtained, and then the static resources in the third information list are deleted, so that the static resources referenced in the output file are determined by the file format of the static resources referenced in the output file, thereby preventing the unreferenced static resources from being missed, improving the accuracy of static resource monitoring, and then improving the accuracy of unreferenced resources in the cleaned project, optimizing the project loading process, and reducing maintenance costs.
[0127] Figure 6 FIG. 1 is a schematic diagram of an electronic device provided by an exemplary embodiment of the present application. Figure 6 As shown, the electronic device 6 of this embodiment includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as a resource cleaning program. When the processor 60 executes the computer program 62, the steps in the above-mentioned resource cleaning method embodiments are implemented, such as Figure 2 Alternatively, when the processor 60 executes the computer program 62, the functions of each unit in the above-mentioned device embodiments are realized, for example Figure 5 The functions of units 501 to 504 are shown.
[0128] Exemplarily, the computer program 62 may be divided into one or more units, which are stored in the memory 61 and executed by the processor 60 to complete the present application. The one or more units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 62 in the electronic device 6. For example, the computer program 62 may be divided into an acquisition unit, an extraction unit, a comparison unit, and a clearing unit, and the specific functions of each module are as follows:
[0129] An acquisition unit 501 is used to acquire a first information list of static resources in a project to be cleared, where the first information list includes relevant information of the static resources in the project;
[0130] An extraction unit 502 is used to extract relevant information of static resources in the output file based on the file format of the static resources referenced in the output file to obtain a second information list, and the output file is an output file generated after the project is packaged;
[0131] A comparing unit 503 is used to compare the first information list with the second information list to obtain a third information list, where the third information list includes relevant information of unused static resources in the output file;
[0132] The clearing unit 504 is used to delete the static resources in the third information list from the resources of the project.
[0133] The electronic device 6 may be any electronic device with a control function. The electronic device 6 may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will appreciate that Figure 6 It is only an example of the electronic device 6 and does not constitute a limitation of the electronic device 6. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 6 may also include input and output devices, network access devices, buses, etc.
[0134] The processor 60 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0135] The memory 61 may be an internal storage unit of the electronic device 6, such as a hard disk or memory of the electronic device 6. The memory 61 may also be an external storage device of the electronic device 6, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 6. Further, the memory 61 may also include both an internal storage unit of the electronic device 6 and an external storage device. The memory 61 is used to store the computer program and other programs and data required by the terminal device. The memory 61 may also be used to temporarily store data that has been output or is to be output.
[0136] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0137] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0138] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0139] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0140] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0141] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0142] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0143] The embodiments of the present application further provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0144] The embodiment of the present application also provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0145] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A resource cleaning method, characterized in that: The method comprises: Obtain a first information list of static resources in the project to be cleaned up, wherein the first information list includes relevant information of the static resources in the project; Extracting relevant information of the static resources in the output file based on the file format of the static resources referenced in the output file to obtain a second information list, wherein the output file is an output file generated after the project is packaged; Comparing the first information list with the second information list to obtain a third information list, wherein the third information list includes relevant information of unused static resources in the output file; The static resources in the third information list are deleted from the resources of the project.
2. The method according to claim 1, characterized in that The step of extracting relevant information of the static resources in the output file based on the file format of the static resources referenced in the output file to obtain a second information list includes: Parse the output file to obtain a first static resource in a web page format and a second static resource in an audio and video format in the output file; Parsing the first static resource to obtain a third static resource in an audio and video format and a fourth static resource in another format from the static resource in the webpage format; The second information list is generated based on the relevant information of the second static resource, the third static resource and the fourth static resource.
3. The method according to claim 2, characterized in that The generating the second information list based on the relevant information of the second static resource, the third static resource and the fourth static resource includes: Determine a coded static resource from the second static resource and the third static resource; Decoding the encoded static resource in the second static resource and the third static resource to obtain the corresponding second static resource in a non-encoded format and the third static resource in a non-encoded format; Querying the relevant information corresponding to the second static resource in non-coding format, the third static resource in non-coding format, and the fourth static resource from the project file of the project to be cleaned up; The second information list is composed of the related information corresponding to the second static resource in non-coding format, the third static resource in non-coding format and the fourth static resource.
4. The method according to claim 1, characterized in that After comparing the first information list and the second information list to obtain a third information list, the method further includes: Generate prompt information based on the third information list, the prompt information is used to prompt the user to delete the static resources corresponding to the third information list; The prompt information is output.
5. The method according to claim 4, characterized in that The deleting the static resources in the third information list from the resources of the project includes: In response to a confirmation operation based on the prompt information, the static resources in the third information list are deleted from the resources of the project.
6. The method according to any one of claims 1 to 5, characterized in that: The deleting the static resources in the third information list from the resources of the project includes: Call resource cleanup function; Based on the resource clearing function, the static resources in the third information list are deleted from the resources of the project.
7. The method according to any one of claims 1 to 5, characterized in that: The obtaining of a first information list of static resources in the project to be cleaned up, wherein the first information list includes relevant information of the static resources in the project, including: Get the project directory of the project to be cleaned up; Traverse the project files of the project based on the project directory to obtain relevant information of static resources in the project; The first information list is generated based on the relevant information of the static resources in the project.
8. A resource cleaning device, characterized in that: The device comprises: An acquiring unit, configured to acquire a first information list of static resources in a project to be cleaned up, wherein the first information list includes relevant information of the static resources in the project; An extraction unit, configured to extract relevant information of static resources in an output file based on a file format of static resources referenced in the output file to obtain a second information list, wherein the output file is an output file generated after the project is packaged; a comparing unit, configured to compare the first information list with the second information list to obtain a third information list, wherein the third information list includes relevant information of unused static resources in the output file; A clearing unit is used to delete the static resources in the third information list from the resources of the project.
9. An electronic device, characterized in that: The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the resource cleaning method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the resource cleaning method according to any one of claims 1 to 7 is implemented.