A method and device for improving the real-time response performance of a cloud management platform
By obtaining and matching HTML and JS code in the cloud management platform and removing redundant code, the poor performance problems caused by redundant code in the cloud management platform development are solved, and more efficient code cleaning and performance improvement are achieved.
Patent Information
- Application Number
- CN202410937185.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-07-12
AI Technical Summary
During the development of the cloud management platform, the redundant code was not accurately discovered and cleaned up, resulting in the problem of low real-time response performance.
By obtaining the HTML code of the cloud management platform, extracting the code in the JS code that is used to dynamically adjust HTML elements, and matching them with the elements in the HTML code, deduplication processing determines the redundant parts in the CSS and JS codes, and then Remove redundant code. This method does not rely on build tools and can fully detect and clean up redundant code.
It effectively improves the real-time response performance of the cloud management platform, improves the maintainability and performance of code, and solves the universality of redundant code detection and cleaning.
Smart Images

Figure CN118502773B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a method and device for improving the real-time response performance of a cloud management platform. Background Art
[0002] In the front-end development process of the cloud management platform, as the scale and complexity of the code continue to increase, the volume of the front-end code is getting larger and larger, which also has a drastic impact on the performance and user experience of the cloud management platform. Optimizing the code volume is becoming more and more important. At present, when reducing redundant code, the front-end is often achieved by using Tree Shaking in build tools such as Webpack and Rollup. According to data, more than 75% of professional developers use build tools in their work. However, this solution has some defects: on the one hand, Tree Shaking mainly relies on static analysis, and dynamic code cannot be analyzed and optimized, which has certain limitations; on the other hand, Tree Shaking is analyzed and optimized at the compilation stage, and will not prompt or modify the original code; and not all projects will use build tools such as Webpack, so the redundant code in these projects cannot be automatically detected, which will directly affect the real-time response performance of the cloud management platform.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present application provide a method and device for improving the real-time response performance of a cloud management platform, so as to at least solve the technical problem that redundant code parts cannot be accurately discovered and cleaned up during the development of the cloud management platform, resulting in low real-time response performance of the final platform.
[0005] According to one aspect of an embodiment of the present application, a method for improving the real-time response performance of a cloud management platform is provided, including: obtaining HTML code corresponding to the cloud management platform, and determining CSS code and JS code on which the HTML code depends; extracting a first code in the JS code for dynamically adjusting HTML elements, and extracting the first code and all first HTML elements in the HTML code; deduplicating all first HTML elements according to element tag attributes to obtain a first HTML element set; extracting all second HTML elements in the CSS code, and matching each second HTML element with the first HTML element set in turn, and determining redundant code in the CSS code based on the matching results obtained; extracting all third HTML elements in the JS code, and matching each third HTML element with the first HTML element set in turn, and determining redundant code in the JS code based on the matching results obtained; and deleting redundant code in the CSS code and redundant code in the JS code.
[0006] Optionally, extracting the first code in the JS code for dynamically adjusting the HTML element, and extracting all the first HTML elements in the first code and the HTML code, includes: extracting the first code in the JS code by regular matching; extracting all the first HTML elements in the first code and the HTML code respectively by regular matching, wherein the first HTML element includes: HTML tags and HTML attributes, and the HTML attributes include at least one of the following: class name, logo, style, event, and execution mode.
[0007] Optionally, all first HTML elements are deduplicated according to element tag attributes to obtain a first HTML element set, including: traversing the HTML tags of all first HTML elements, deduplicating if identical HTML tags exist, and obtaining an HTML tag set; traversing the HTML attributes of all first HTML elements, adding each HTML attribute to a corresponding HTML tag in the HTML tag set, deduplicating if identical HTML attributes exist, and obtaining the first HTML element set.
[0008] Optionally, all second HTML elements in the CSS code are extracted, and each second HTML element is matched with the first HTML element set in turn, and redundant code in the CSS code is determined according to the obtained matching results, including: extracting all second HTML elements in the CSS code by regular matching; for each second HTML element, determining whether there is a first HTML element matching the second HTML element in the first HTML element set; if there is no first HTML element matching the second HTML element in the first HTML element set, determining that the code fragment corresponding to the second HTML element is redundant code.
[0009] Optionally, all third HTML elements in the JS code are extracted, and each third HTML element is matched with the first HTML element set in turn, and redundant code in the JS code is determined based on the obtained matching results, including: extracting all third HTML elements in the JS code through regular matching, wherein the types of the third HTML elements include: non-function code blocks and function code blocks, and the non-function code blocks include: variable declarations and processing methods for declared variables; matching each function code block with the first HTML element set in turn, and determining redundant function code blocks and non-redundant function code block sets based on the obtained matching results; matching each non-function code block with the first HTML element set and / or the non-redundant function code block set in turn, and determining redundant non-function code blocks based on the obtained matching results.
[0010] Optionally, each function class code block is matched with the first HTML element set in turn, and a redundant function class code block and a non-redundant function class code block set are determined based on the obtained matching results, including: for each function class code block, determining whether the function class code block is related to a JS event; if the function class code block is related to a JS event, determining whether there is a first HTML element in the first HTML element set that matches the JS event body corresponding to the function class code block; if the function class code block is not related to the JS event, determining whether there is a first HTML element in the first HTML element set that matches the execution mode corresponding to the function class code block; if there is no first HTML element in the first HTML element set that matches the JS event body or execution mode corresponding to the function class code block, determining that the function class code block is a redundant function class code block; if there is a first HTML element in the first HTML element set that matches the JS event body or execution mode corresponding to the function class code block, determining that the function class code block is a non-redundant function class code block, and forming all non-redundant function class code blocks into a non-redundant function class code block set.
[0011] Optionally, each non-function class code block is matched with the first HTML element set and / or the non-redundant function class code block set in turn, and redundant non-function class code blocks are determined based on the matching results, including: for each non-function class code block, determining whether there is a first HTML element in the first HTML element set that matches the declaration method corresponding to the non-function class code block; if there is no first HTML element in the first HTML element set that matches the declaration method corresponding to the non-function class code block, determining whether the non-function class code block is called by a non-redundant function class code block in the non-redundant function class code block set; if the non-function class code block is not called by a non-redundant function class code block in the non-redundant function class code block set, determining that the non-function class code block is a redundant non-function class code block.
[0012] Optionally, deleting redundant code in the CSS code and redundant code in the JS code includes: sending a notification message to the target object, wherein the notification message includes the redundant code in the CSS code and redundant code in the JS code, and the notification message is used to prompt the target object to delete the redundant code; or, automatically deleting the redundant code in the CSS code and redundant code in the JS code, and sending code deletion log information to the target object.
[0013] According to another aspect of the embodiment of the present application, a device for improving the real-time response performance of a cloud management platform is also provided, including: an acquisition module, used to acquire the HTML code corresponding to the cloud management platform, and determine the CSS code and JS code on which the HTML code depends; an extraction module, used to extract the first code in the JS code for dynamically adjusting the HTML element, and extract the first code and all the first HTML elements in the HTML code; a deduplication module, used to dedupe all the first HTML elements according to the element tag attributes to obtain a first HTML element set; a first detection module, used to extract all the second HTML elements in the CSS code, and match each of the second HTML elements with the first HTML element set in turn, and determine the redundant code in the CSS code based on the obtained matching results; a second detection module, used to extract all the third HTML elements in the JS code, and match each of the third HTML elements with the first HTML element set in turn, and determine the redundant code in the JS code based on the obtained matching results; a processing module, used to delete the redundant code in the CSS code and the redundant code in the JS code.
[0014] According to another aspect of an embodiment of the present application, an electronic device is also provided, which includes: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned method for improving the real-time response performance of the cloud management platform through the computer program.
[0015] In the embodiment of the present application, first obtain the HTML code corresponding to the cloud management platform, and determine the CSS code and JS code that the HTML code depends on; extract the first code in the JS code for dynamically adjusting the HTML element, and extract the first code and all the first HTML elements in the HTML code; then deduplicate all the first HTML elements according to the element tag attributes to obtain a first HTML element set; extract all the second HTML elements in the CSS code, and extract all the third HTML elements in the JS code, match each second HTML element and each third HTML element with the first HTML element set in turn, determine the redundant code in the CSS code and JS code based on the matching results; delete the redundant code. This solution takes into account both HTML static code and dynamic code, which can help developers comprehensively detect and clean up redundant code in the development process, and this solution does not rely on build tools, has universality, and effectively solves the technical problem that the redundant parts of the code cannot be accurately discovered and cleaned up during the development of the cloud management platform, resulting in low real-time response performance of the final platform. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 It is a flowchart of an optional method for improving the real-time response performance of a cloud management platform according to an embodiment of the present application;
[0018] Figure 2 It is a structural schematic diagram of an optional device for improving the real-time response performance of a cloud management platform according to an embodiment of the present application;
[0019] Figure 3 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0021] It should be noted that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] In order to better understand the embodiments of the present application, some nouns or terms that appear in the description of the embodiments of the present application are first translated and explained as follows:
[0023] HTML (Hyper Text Markup Language): A standard markup language used to create web pages and web applications.
[0024] CSS (Cascading Style Sheets): used to describe the layout, appearance and format of web pages.
[0025] JS (JavaScript): A widely used scripting language, mainly used to enhance the interactivity of web pages.
[0026] DOM (Document Object Model): A programming interface for processing HTML documents.
[0027] Regular matching: Use regular expressions to search, identify, and extract strings in text that conform to specific grammatical rules.
[0028] Example 1
[0029] According to an embodiment of the present application, a method for improving the real-time response performance of a cloud management platform is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] Figure 1 is a flow chart of a method for improving the real-time response performance of a cloud management platform provided in an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0031] Step S102, obtaining the HTML code corresponding to the cloud management platform, and determining the CSS code and JS code that the HTML code depends on;
[0032] Step S104, extracting the first code for dynamically adjusting the HTML element in the JS code, and extracting all the first HTML elements in the first code and the HTML code;
[0033] Step S106, performing deduplication processing on all first HTML elements according to element tag attributes to obtain a first HTML element set;
[0034] Step S108, extracting all second HTML elements in the CSS code, and matching each second HTML element with the first HTML element set in turn, and determining redundant codes in the CSS code according to the obtained matching results;
[0035] Step S110, extracting all third HTML elements in the JS code, and matching each third HTML element with the first HTML element set in turn, and determining redundant code in the JS code according to the obtained matching results;
[0036] Step S112, deleting redundant codes in the CSS code and redundant codes in the JS code.
[0037] The following describes the steps of the method for improving the real-time response performance of the cloud management platform in combination with the specific implementation process.
[0038] As an optional implementation method, first obtain the HTML code of the web page or web application in the front-end development process of the cloud management platform, the HTML code is a static code, and then obtain the CSS code and JS code that the HTML code depends on, such as through <link> or <script>标签引入的外部CSS代码和JS代码。
[0039] 为了更全面地对开发过程中的冗余代码进行检测,本申请实施例还对HTML代码相关的动态代码进行了分析。
[0040] 可选地,可以通过如下方式提取JS代码中用于动态调整HTML元素的第一代码,并提取第一代码和HTML代码中的所有第一HTML元素:通过正则匹配提取JS代码中的第一代码,该第一代码可以是动态加入HTML元素的代码,或是动态修改HTML元素属性的代码;然后通过正则匹配分别提取第一代码和HTML代码中的所有第一HTML元素,其中,第一HTML元素中包括:HTML标签和HTML属性,HTML属性可以包括:类名(class)、标识(id)、样式(style)、事件、执行方式等。
[0041] 之后,可以将所有第一HTML元素按照元素标签属性进行去重处理,具体方式如下:遍历所有第一HTML元素的HTML标签,若存在相同的HTML标签则进行去重,得到HTML标签集合;遍历所有第一HTML元素的HTML属性,将各个HTML属性添加至HTML标签集合中对应的HTML标签,若存在相同的HTML属性则进行去重,得到第一HTML元素集合。
[0042] 例如,可以从根HTML元素开始依次向下递归遍历每个HTML元素的标签,每检测到一个新的HTML标签,则将该HTML标签放入容器A中,相同的HTML标签不重复加入,此时得到的容器A中存储有去重后的HTML标签,也即HTML标签集合,该容器A中的每个HTML标签可以视为一个子容器a;之后,再次从根HTML元素开始依次向下递归遍历每个HTML元素的属性,每检测到一个HTML元素新的属性,则将该HTML属性添加至容器A中对应HTML标签的子容器a中,相同的HTML属性不重复添加,最后得到的容器A中即存储有去重后的HTML标签和每个HTML标签对应的去重后的HTML属性,也即第一HTML元素集合。
[0043] 可选地,得到第一HTML元素集合之后,即可以此为依据,分别检测CSS代码和JS代码中的冗余代码。
[0044] 作为一种可选的实施方式,可以通过如下方式检测CSS代码中的冗余代码:通过正则匹配提取CSS代码中的所有第二HTML元素;对于每个第二HTML元素,确定第一HTML元素集合中是否存在与第二HTML元素相匹配的第一HTML元素;若第一HTML元素集合中不存在与第二HTML元素相匹配的第一HTML元素,确定第二HTML元素对应的代码片段为冗余代码。
[0045] 通常,在CSS代码中,大括号{}内的内容用于定义规则集或声明块,而大括号{}外的内容为选择器,用于指定CSS规则集将应用于哪些HTML元素中,也就是我们需要提取的第二HTML元素。根据以上特性,可以先匹配开始符号{,然后匹配该开始符号{之前的代码,一直匹配到开始符号{的上一个结束符号},匹配到的中间的内容即为一个第二HTML元素,其中包括有HTML标签名、类名、标识等,可以将检测到的每个第二HTML元素作为一个子容器b放入容器B中。
[0046] 之后,对于容器B中的每个子容器b,可以将该子容器b与容器A中的每个子容器a进行比对,若存在相同的子容器a,则对该子容器b进行标记,最后筛选出所有未被标记的子容器b放入容器UDCSS中,容器UDCSS中的子容器b对应的代码片段即为CSS代码中的冗余代码。
[0047] 作为一种可选的实施方式,可以通过如下方式检测JS代码中的冗余代码:通过正则匹配提取JS代码中的所有第三HTML元素,其中,第三HTML元素的类型包括:非函数类代码块和函数类代码块,非函数类代码块包括:变量声明、对已声明变量的处理方式;依次将各个函数类代码块与第一HTML元素集合进行匹配,依据得到的匹配结果确定冗余函数类代码块以及非冗余函数类代码块集合;依次将各个非函数类代码块与第一HTML元素集合和 / 或非冗余函数类代码块集合进行匹配,依据得到的匹配结果确定冗余非函数类代码块。
[0048] 具体地,JS代码可分为两种,一种属于函数类,一种是非函数类,可以将每一段非函数类的代码理解为一块代码块,每一个函数类的函数整体理解为一块代码块。由于函数类代码块中通常包括:function{}关键字或 ()=>{}或 [变量](){},可根据此特性使用正则表达式从上至下依次匹配未被包裹在函数内的代码块为非函数类代码块,将其放至容器X1中,匹配包裹在函数内的代码块与函数本身共同作为函数类代码块,将其放至容器X2中。
[0049] 可选地,在确定函数类代码块对应的冗余代码时,可以通过如下方式进行:对于每个函数类代码块,确定函数类代码块是否与JS事件相关;若函数类代码块与JS事件相关,确定第一HTML元素集合中是否存在与函数类代码块对应的JS事件主体相匹配的第一HTML元素;若函数类代码块与JS事件不相关,确定第一HTML元素集合中是否存在与函数类代码块对应的执行方式相匹配的第一HTML元素;若第一HTML元素集合中不存在与函数类代码块对应的JS事件主体或执行方式相匹配的第一HTML元素,确定函数类代码块为冗余函数类代码块;若第一HTML元素集合中存在与函数类代码块对应的JS事件主体或执行方式相匹配的第一HTML元素,确定函数类代码块为非冗余函数类代码块,将所有非冗余函数类代码块组成非冗余函数类代码块集合。
[0050] 其中,事件主体是指JS中的鼠标事件、键盘事件、表单事件、拖放事件、触摸事件、窗口事件、剪切板事件、焦点事件、自定义事件、或是其他诸如资源中止、资源加载失败、右键菜单、鼠标滚轮、CSS动画类事件等,每一个事件都对应有关键字,例如鼠标事件-点击事件对应关键字click,鼠标事件-滚轮事件对应关键字wheel等。
[0051] 对于容器X2中的每个函数类代码块,可以通过关键字检索确定该函数类代码块对应的JS事件主体,然后依次确定容器A中的各个子容器a中是否有与之匹配的JS事件主体,若存在相匹配的JS事件主体,则标记该函数类代码块,将其放入容器X3,也即非冗余函数类代码块集合中;若该函数类代码块未挂载在JS事件上,还可以确定该函数类代码块对应的执行方式,然后依次确定容器A中的各个子容器a中是否有与之匹配的执行方式,若存在相匹配的执行方式,则标记该函数类代码块,将其放入容器X3中;最后筛选出所有未被标记的函数类代码块放入容器UDJS中,容器UDJS中的函数类代码块即为冗余函数类代码块。
[0052] 可选地,在确定非函数类代码块对应的冗余代码时,可以通过如下方式进行:对于每个非函数类代码块,确定第一HTML元素集合中是否存在与非函数类代码块对应的声明方式相匹配的第一HTML元素;若第一HTML元素集合中不存在与非函数类代码块对应的声明方式相匹配的第一HTML元素,确定非函数类代码块是否被非冗余函数类代码块集合中的非冗余函数类代码块所调用;若非函数类代码块未被非冗余函数类代码块集合中的非冗余函数类代码块所调用,确定非函数类代码块为冗余非函数类代码块。
[0053] 具体地,对于容器X1中的每个非函数类代码块,可以先筛选出其中的DOM节点声明类代码,根据其声明方式,如标签声明、类名声明、标识声明等,在容器A中的各个子容器a中查找是否有与之匹配的元素,若存在与之匹配的元素,则标记该非函数类代码块;对于未被标记的非函数类代码块,例如Number、Boolean、String、Array、Object、Null、Undefined等类型变量,可以根据变量是运算符和关键字结合使用的特性,结合正则确定这些未被标记的非函数类代码块是否被容器X3中的非冗余函数类代码块所调用,标记被调用的非函数类代码块,将最终剩下的所有未被标记的非函数类代码块放入容器UDJS中,容器UDJS中的非函数类代码块即为冗余非函数类代码块。
[0054] 在检测出CSS代码和JS代码中的冗余代码之后,可以向目标对象发送通知消息,其中,目标对象为前端开发人员,通知消息中包括检测得到的CSS代码中的冗余代码和JS代码中的冗余代码,该通知消息用于提示目标对象对冗余代码进行删除,以便于缩小代码体积,提高代码可维护性。
[0055] 在一种更加智能的场景中,还可以自动化删除检测得到的CSS代码中的冗余代码和JS代码中的冗余代码,并在处理完成后向目标对象发送代码删除日志信息。
[0056] 在本申请实施例中,首先获取云管平台对应的HTML代码,并确定该HTML代码依赖的CSS代码和JS代码;提取JS代码中用于动态调整HTML元素的第一代码,并提取第一代码和HTML代码中的所有第一HTML元素;然后将所有第一HTML元素按照元素标签属性进行去重处理,得到第一HTML元素集合;提取CSS代码中的所有第二HTML元素,并提取JS代码中的所有第三HTML元素,依次将各个第二HTML元素和各个第三HTML元素与第一HTML元素集合进行匹配,依据得到的匹配结果确定CSS代码和JS代码中的冗余代码;删除冗余代码。该方案同时考虑HTML静态代码和动态代码,可以帮助开发人员全面检测并清理开发过程的冗余代码,且该方案不依赖于构建工具,具有通行性,有效解决了云管平台开发过程中未能准确发现并清理代码冗余部分,导致最终平台实时响应性能较低的技术问题。
[0057] 实施例2
[0058] 根据本申请实施例,还提供了一种用于实现实施例1中的提升云管平台实时响应性能的方法的提升云管平台实时响应性能的装置,如图2所示,该提升云管平台实时响应性能的装置中至少包括:获取模块21、提取模块22、去重模块23、第一检测模块24、第二检测模块25和处理模块26,其中:
[0059] 获取模块21,用于获取超文本标记语言HTML代码,并确定HTML代码依赖的层叠样式表CSS代码和JS代码;
[0060] 提取模块22,用于提取JS代码中用于动态调整HTML元素的第一代码,并提取第一代码和HTML代码中的所有第一HTML元素;
[0061] 去重模块23,用于将所有第一HTML元素按照元素标签属性进行去重处理,得到第一HTML元素集合;
[0062] 第一检测模块24,用于提取CSS代码中的所有第二HTML元素,并依次将各个第二HTML元素与第一HTML元素集合进行匹配,依据得到的匹配结果确定CSS代码中的冗余代码;
[0063] 第二检测模块25,用于提取JS代码中的所有第三HTML元素,并依次将各个第三HTML元素与第一HTML元素集合进行匹配,依据得到的匹配结果确定JS代码中的冗余代码;
[0064] 处理模块26,用于删除CSS代码中的冗余代码和JS代码中的冗余代码。
[0065] 以下结合具体的实施过程对提升云管平台实时响应性能的装置的各模块功能进行说明。
[0066] 作为一种可选的实施方式,获取模块可以获取云管平台在前端开发过程的网页或网页应用的HTML代码,该HTML代码为静态代码,再获取该HTML代码所依赖的CSS代码和JS代码,如通过<link>或<script>标签引入的外部CSS代码和JS代码。
[0067] 为了更全面地对开发过程中的冗余代码进行检测,本申请实施例综合对HTML静态代码和动态代码进行分析。
[0068] 可选地,提取模块可以通过如下方式提取JS代码中用于动态调整HTML元素的第一代码,并提取第一代码和HTML代码中的所有第一HTML元素:通过正则匹配提取JS代码中的第一代码,该第一代码可以是动态加入HTML元素的代码,或是动态修改HTML元素属性的代码;然后通过正则匹配分别提取第一代码和HTML代码中的所有第一HTML元素,其中,第一HTML元素中包括:HTML标签和HTML属性,HTML属性可以包括:类名、标识、样式、事件、执行方式等。
[0069] 之后,去重模块可以将所有第一HTML元素按照元素标签属性进行去重处理,具体方式如下:遍历所有第一HTML元素的HTML标签,若存在相同的HTML标签则进行去重,得到HTML标签集合;遍历所有第一HTML元素的HTML属性,将各个HTML属性添加至HTML标签集合中对应的HTML标签,若存在相同的HTML属性则进行去重,得到第一HTML元素集合。
[0070] 例如,可以从根HTML元素开始依次向下递归遍历每个HTML元素的标签,每检测到一个新的HTML标签,则将该HTML标签放入容器A中,相同的HTML标签不重复加入,此时得到的容器A中存储有去重后的HTML标签,也即HTML标签集合,该容器A中的每个HTML标签可以视为一个子容器a;之后,再次从根HTML元素开始依次向下递归遍历每个HTML元素的属性,每检测到一个HTML元素新的属性,则将该HTML属性添加至容器A中对应HTML标签的子容器a中,相同的HTML属性不重复添加,最后得到的容器A中即存储有去重后的HTML标签和每个HTML标签对应的去重后的HTML属性,也即第一HTML元素集合。
[0071] 可选地,得到第一HTML元素集合之后,即可以此为依据,分别检测CSS代码和JS代码中的冗余代码。
[0072] 作为一种可选的实施方式,第一检测模块可以通过如下方式检测CSS代码中的冗余代码:通过正则匹配提取CSS代码中的所有第二HTML元素;对于每个第二HTML元素,确定第一HTML元素集合中是否存在与第二HTML元素相匹配的第一HTML元素;若第一HTML元素集合中不存在与第二HTML元素相匹配的第一HTML元素,确定第二HTML元素对应的代码片段为冗余代码。
[0073] 通常,在CSS代码中,大括号{}内的内容用于定义规则集或声明块,而大括号{}外的内容为选择器,用于指定CSS规则集将应用于哪些HTML元素中,也就是我们需要提取的第二HTML元素。根据以上特性,可以先匹配开始符号{,然后匹配该开始符号{之前的代码,一直匹配到开始符号{的上一个结束符号},匹配到的中间的内容即为一个第二HTML元素,其中包括有HTML标签名、类名、标识等,可以将检测到的每个第二HTML元素作为一个子容器b放入容器B中。
[0074] 之后,对于容器B中的每个子容器b,可以将该子容器b与容器A中的每个子容器a进行比对,若存在相同的子容器a,则对该子容器b进行标记,最后筛选出所有未被标记的子容器b放入容器UDCSS中,容器UDCSS中的子容器b对应的代码片段即为CSS代码中的冗余代码。
[0075] 作为一种可选的实施方式,第二检测模块可以通过如下方式检测JS代码中的冗余代码:通过正则匹配提取JS代码中的所有第三HTML元素,其中,第三HTML元素的类型包括:非函数类代码块和函数类代码块,非函数类代码块包括:变量声明、对已声明变量的处理方式;依次将各个函数类代码块与第一HTML元素集合进行匹配,依据得到的匹配结果确定冗余函数类代码块以及非冗余函数类代码块集合;依次将各个非函数类代码块与第一HTML元素集合和 / 或非冗余函数类代码块集合进行匹配,依据得到的匹配结果确定冗余非函数类代码块。
[0076] 具体地,JS代码可分为两种,一种属于函数类,一种是非函数类,可以将每一段非函数类的代码理解为一块代码块,每一个函数类的函数整体理解为一块代码块。由于函数类代码块中通常包括:function{}关键字或 ()=>{}或 [变量](){},可根据此特性使用正则表达式从上至下依次匹配未被包裹在函数内的代码块为非函数类代码块,将其放至容器X1中,匹配包裹在函数内的代码块与函数本身共同作为函数类代码块,将其放至容器X2中。
[0077] 可选地,第二检测模块在确定函数类代码块对应的冗余代码时,可以通过如下方式进行:对于每个函数类代码块,确定函数类代码块是否与JS事件相关;若函数类代码块与JS事件相关,确定第一HTML元素集合中是否存在与函数类代码块对应的JS事件主体相匹配的第一HTML元素;若函数类代码块与JS事件不相关,确定第一HTML元素集合中是否存在与函数类代码块对应的执行方式相匹配的第一HTML元素;若第一HTML元素集合中不存在与函数类代码块对应的JS事件主体或执行方式相匹配的第一HTML元素,确定函数类代码块为冗余函数类代码块;若第一HTML元素集合中存在与函数类代码块对应的JS事件主体或执行方式相匹配的第一HTML元素,确定函数类代码块为非冗余函数类代码块,将所有非冗余函数类代码块组成非冗余函数类代码块集合。
[0078] 其中,事件主体是指JS中的鼠标事件、键盘事件、表单事件、拖放事件、触摸事件、窗口事件、剪切板事件、焦点事件、自定义事件、或是其他诸如资源中止、资源加载失败、右键菜单、鼠标滚轮、CSS动画类事件等,每一个事件都对应有关键字,例如鼠标事件-点击事件对应关键字click,鼠标事件-滚轮事件对应关键字wheel等。
[0079] 对于容器X2中的每个函数类代码块,可以通过关键字检索确定该函数类代码块对应的JS事件主体,然后依次确定容器A中的各个子容器a中是否有与之匹配的JS事件主体,若存在相匹配的JS事件主体,则标记该函数类代码块,将其放入容器X3,也即非冗余函数类代码块集合中;若该函数类代码块未挂载在JS事件上,还可以确定该函数类代码块对应的执行方式,然后依次确定容器A中的各个子容器a中是否有与之匹配的执行方式,若存在相匹配的执行方式,则标记该函数类代码块,将其放入容器X3中;最后筛选出所有未被标记的函数类代码块放入容器UDJS中,容器UDJS中的函数类代码块即为冗余函数类代码块。
[0080] 可选地,第二检测模块在确定非函数类代码块对应的冗余代码时,可以通过如下方式进行:对于每个非函数类代码块,确定第一HTML元素集合中是否存在与非函数类代码块对应的声明方式相匹配的第一HTML元素;若第一HTML元素集合中不存在与非函数类代码块对应的声明方式相匹配的第一HTML元素,确定非函数类代码块是否被非冗余函数类代码块集合中的非冗余函数类代码块所调用;若非函数类代码块未被非冗余函数类代码块集合中的非冗余函数类代码块所调用,确定非函数类代码块为冗余非函数类代码块。
[0081] 具体地,对于容器X1中的每个非函数类代码块,可以先筛选出其中的DOM节点声明类代码,根据其声明方式,如标签声明、类名声明、标识声明等,在容器A中的各个子容器a中查找是否有与之匹配的元素,若存在与之匹配的元素,则标记该非函数类代码块;对于未被标记的非函数类代码块,例如Number、Boolean、String、Array、Object、Null、Undefined等类型变量,可以根据变量是运算符和关键字结合使用的特性,结合正则确定这些未被标记的非函数类代码块是否被容器X3中的非冗余函数类代码块所调用,标记被调用的非函数类代码块,将最终剩下的所有未被标记的非函数类代码块放入容器UDJS中,容器UDJS中的非函数类代码块即为冗余非函数类代码块。
[0082] 在检测出CSS代码和JS代码中的冗余代码之后,处理模块可以向目标对象发送通知消息,其中,目标对象为前端开发人员,通知消息中包括检测得到的CSS代码中的冗余代码和JS代码中的冗余代码,该通知消息用于提示目标对象对冗余代码进行删除,以便于缩小代码体积,提高代码可维护性。
[0083] 在一种更加智能的场景中,处理模块还可以自动化删除检测得到的CSS代码中的冗余代码和JS代码中的冗余代码,并在处理完成后向目标对象发送代码删除日志信息。
[0084] 需要说明的是,本申请实施例中的提升云管平台实时响应性能的装置中的各模块与实施例1中的提升云管平台实时响应性能的方法的各实施步骤一一对应,由于实施例1中已经进行了详尽的描述,本实施例中部分未体现的细节可以参考实施例1,在此不再过多赘述。
[0085] 实施例3
[0086] 根据本申请实施例,还提供了一种计算机程序产品,该计算机程序产品包括计算机程序,其中,计算机程序被处理器执行时实现实施例1中的提升云管平台实时响应性能的方法。
[0087] 根据本申请实施例,还提供了一种非易失性存储介质,该非易失性存储介质包括存储的计算机程序,其中,非易失性存储介质所在设备通过运行该计算机程序执行实施例1中的提升云管平台实时响应性能的方法。
[0088] 根据本申请实施例,还提供了一种处理器,该处理器用于运行计算机程序,其中,计算机程序运行时执行实施例1中的提升云管平台实时响应性能的方法。
[0089] 根据本申请实施例,还提供了一种电子设备,该电子设备包括:存储器和处理器,其中,存储器中存储有计算机程序,处理器被配置为通过计算机程序执行实施例1中的提升云管平台实时响应性能的方法。
[0090] 具体地,计算机程序运行时执行实现以下步骤:获取云管平台对应的HTML代码,并确定HTML代码依赖的CSS代码和JS代码;提取JS代码中用于动态调整HTML元素的第一代码,并提取第一代码和HTML代码中的所有第一HTML元素;将所有第一HTML元素按照元素标签属性进行去重处理,得到第一HTML元素集合;提取CSS代码中的所有第二HTML元素,并依次将各个第二HTML元素与第一HTML元素集合进行匹配,依据得到的匹配结果确定CSS代码中的冗余代码;提取JS代码中的所有第三HTML元素,并依次将各个第三HTML元素与第一HTML元素集合进行匹配,依据得到的匹配结果确定JS代码中的冗余代码;删除CSS代码中的冗余代码和JS代码中的冗余代码。
[0091] 作为一种可选的实施方式,上述电子设备可以以移动终端、计算机终端或者类似的运算装置形式存在。图3示出了一种用于实现提升云管平台实时响应性能的方法的电子设备的硬件结构框图。如图3所示,电子设备30可以包括一个或多个(图中采用302a、302b,……,302n来示出)处理器302(处理器302可以包括但不限于微处理器MCU或可编程逻辑器件FPGA等的处理装置)、用于存储数据的存储器304、以及用于通信功能的传输装置306。除此以外,还可以包括:显示器、输入 / 输出接口(I / O接口)、通用串行总线(USB)端口(可以作为BUS总线的端口中的一个端口被包括)、网络接口、电源和 / 或相机。本领域普通技术人员可以理解,图3所示的结构仅为示意,其并不对上述电子设备的结构造成限定。例如,电子设备30还可包括比图3中所示更多或者更少的组件,或者具有与图3所示不同的配置。
[0092] 应当注意到的是上述一个或多个处理器302和 / 或其他数据处理电路在本文中通常可以被称为"数据处理电路”。该数据处理电路可以全部或部分的体现为软件、硬件、固件或其他任意组合。此外,数据处理电路可为单个独立的处理模块,或全部或部分的结合到电子设备30中的其他元件中的任意一个内。如本申请实施例中所涉及到的,该数据处理电路作为一种处理器控制(例如与接口连接的可变电阻终端路径的选择)。
[0093] 存储器304可用于存储应用软件的软件程序以及模块,如本申请实施例中的提升云管平台实时响应性能的方法对应的程序指令 / 数据存储装置,处理器302通过运行存储在存储器304内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述的应用程序的漏洞检测方法。存储器304可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器304可进一步包括相对于处理器302远程设置的存储器,这些远程存储器可以通过网络连接至电子设备30。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
[0094] 传输装置306用于经由一个网络接收或者发送数据。上述的网络具体实例可包括电子设备30的通信供应商提供的无线网络。在一个实例中,传输装置306包括一个网络适配器(Network Interface Controller,NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输装置306可以为射频(Radio Frequency,RF)模块,其用于通过无线方式与互联网进行通讯。
[0095] 显示器可以例如触摸屏式的液晶显示器(LCD),该液晶显示器可使得用户能够与电子设备30的用户界面进行交互。
[0096] 上述实施例序号仅仅为了描述,不代表实施例的优劣。
[0097] 在本申请的上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。
[0098] 在本申请所提供的几个实施例中,应该理解到,所揭露的技术内容,可通过其它的方式实现。其中,以上所描述的装置实施例仅仅是示意性的,例如单元的划分,可以为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,单元或模块的间接耦合或通信连接,可以是电性或其它的形式。
[0099] 作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
[0100] 另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
[0101] 集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
[0102] 以上仅是本申请的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本申请的保护范围。< / script>
Claims
1. A method for improving the real-time response performance of a cloud management platform, characterized in that: include: Obtain the Hypertext Markup Language HTML code corresponding to the cloud management platform, and determine the Cascading Style Sheet CSS code and JS code that the HTML code depends on; Extracting a first code for dynamically adjusting an HTML element from the JS code, and extracting all first HTML elements from the first code and the HTML code, wherein the first HTML element includes: an HTML tag and an HTML attribute, and the HTML attribute includes at least one of the following: a class name, an identifier, a style, an event, and an execution mode; De-duplicate all the first HTML elements according to element tag attributes to obtain a first HTML element set; Extract all second HTML elements in the CSS code, and match each of the second HTML elements with the first HTML element set in turn, and determine the redundant code in the CSS code according to the obtained matching results, wherein the second HTML elements include: HTML tag name, class name, and logo; Extract all third HTML elements in the JS code, and match each of the third HTML elements with the first HTML element set in turn, and determine the redundant code in the JS code according to the obtained matching results, wherein the types of the third HTML elements include: non-function code blocks and function code blocks, and the non-function code blocks include: variable declarations and processing methods for declared variables; The redundant codes in the CSS code and the redundant codes in the JS code are deleted.
2. The method according to claim 1, characterized in that Extracting a first code for dynamically adjusting HTML elements from the JS code, and extracting all first HTML elements from the first code and the HTML code, including: Extract the first code in the JS code through regular matching; The first code and all the first HTML elements in the HTML code are extracted respectively through regular matching.
3. The method according to claim 2, characterized in that All the first HTML elements are deduplicated according to element tag attributes to obtain a first HTML element set, including: Traverse all HTML tags of the first HTML element, and remove duplicate HTML tags if they exist, to obtain an HTML tag set; The HTML attributes of all the first HTML elements are traversed, and each of the HTML attributes is added to a corresponding HTML tag in the HTML tag set. If the same HTML attributes exist, duplicates are removed to obtain the first HTML element set.
4. The method according to claim 1, characterized in that: Extracting all second HTML elements in the CSS code, and matching each of the second HTML elements with the first HTML element set in turn, and determining redundant codes in the CSS code according to the obtained matching results, including: Extract all the second HTML elements in the CSS code through regular matching; For each of the second HTML elements, determining whether there is a first HTML element matching the second HTML element in the first HTML element set; If there is no first HTML element matching the second HTML element in the first HTML element set, it is determined that the code fragment corresponding to the second HTML element is redundant code.
5. The method according to claim 2, characterized in that: Extracting all third HTML elements in the JS code, and matching each of the third HTML elements with the first HTML element set in turn, and determining redundant code in the JS code according to the obtained matching results, including: Extract all the third HTML elements in the JS code through regular matching; Matching each of the function class code blocks with the first HTML element set in sequence, and determining a redundant function class code block and a non-redundant function class code block set according to the obtained matching results; Each of the non-function code blocks is matched with the first HTML element set and / or the non-redundant function code block set in sequence, and redundant non-function code blocks are determined according to the obtained matching results.
6. The method according to claim 5, characterized in that Matching each of the function class code blocks with the first HTML element set in sequence, and determining redundant function class code blocks and a non-redundant function class code block set according to the obtained matching results, including: For each of the function class code blocks, determining whether the function class code block is related to a JS event; If the function class code block is related to a JS event, determining whether there is a first HTML element in the first HTML element set that matches the JS event body corresponding to the function class code block; If the function class code block is not related to the JS event, determining whether there is a first HTML element in the first HTML element set that matches the execution mode corresponding to the function class code block; If there is no first HTML element in the first HTML element set that matches the JS event body or execution mode corresponding to the function class code block, determine that the function class code block is a redundant function class code block; If there is a first HTML element in the first HTML element set that matches the JS event body or execution method corresponding to the function class code block, determine that the function class code block is a non-redundant function class code block, and form all the non-redundant function class code blocks into the non-redundant function class code block set.
7. The method according to claim 5, characterized in that Sequentially matching each of the non-function code blocks with the first HTML element set and / or the non-redundant function code block set, and determining redundant non-function code blocks according to the obtained matching results, including: For each of the non-function code blocks, determining whether there is a first HTML element in the first HTML element set that matches the declaration method corresponding to the non-function code block; If there is no first HTML element in the first HTML element set that matches the declaration mode corresponding to the non-function code block, determining whether the non-function code block is called by a non-redundant function code block in the non-redundant function code block set; If the non-function code block is not called by a non-redundant function code block in the non-redundant function code block set, it is determined that the non-function code block is a redundant non-function code block.
8. The method according to claim 1, characterized in that: Deleting redundant codes in the CSS code and redundant codes in the JS code includes: Sending a notification message to the target object, wherein the notification message includes the redundant code in the CSS code and the redundant code in the JS code, and the notification message is used to prompt the target object to delete the redundant code; or, Automatically delete redundant codes in the CSS code and redundant codes in the JS code, and send code deletion log information to the target object.
9. A device for improving the real-time response performance of a cloud management platform, characterized in that: include: An acquisition module is used to acquire the HTML code corresponding to the cloud management platform and determine the CSS code and JS code that the HTML code depends on; An extraction module is used to extract a first code for dynamically adjusting HTML elements from the JS code, and extract the first code and all first HTML elements from the HTML code, wherein the first HTML element includes: an HTML tag and an HTML attribute, and the HTML attribute includes at least one of the following: a class name, an identifier, a style, an event, and an execution mode; A deduplication module, used for deduplicating all the first HTML elements according to element tag attributes to obtain a first HTML element set; A first detection module is used to extract all second HTML elements in the CSS code, and sequentially match each of the second HTML elements with the first HTML element set, and determine the redundant code in the CSS code according to the obtained matching results, wherein the second HTML elements include: HTML tag name, class name, and logo; a second detection module, configured to extract all third HTML elements in the JS code, and sequentially match each of the third HTML elements with the first HTML element set, and determine redundant code in the JS code according to the obtained matching results, wherein the types of the third HTML elements include: non-function code blocks and function code blocks, and the non-function code blocks include: variable declarations and methods for processing declared variables; The processing module is used to delete the redundant codes in the CSS code and the redundant codes in the JS code.
10. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the method for improving the real-time response performance of the cloud management platform as described in any one of claims 1 to 8 through the computer program.
