| In recent years,Web application scenarios have become more and more abundant,and application functions have become more and more complex.Many websites import large-scale JavaScript libraries to speed up development efficiency and enhance user experience.However,many JavaScript libraries are only partially utilized during page loading,but they are all packaged in bundles.Redundant JavaScript code increases the weight of the page,which increases the time to download,parse and compile JavaScript resources.Therefore,it is very important to optimize the payload of JavaScript resources to improve Web performance.The analysis granularity of existing modular reduction schemes is large,and there is still a lot of redundancy in function granularity.In addition,static analysis is difficult to identify the dynamic characteristics of JavaScript,and dynamic analysis is limited by test coverage,which is prone to false positives.A single analysis type is not enough to identify more accurate redundant code.In order to solve the above problems,this thesis proposes a hybrid analysis method combining static structure analysis and dynamic tracking technology to identify redundant code in the application,and implements a tool to optimize the size of application deployment package.The main research results are reflected in the following three aspects:(1)A multi-level static analysis structure is designed to construct the function call graph,which can simplify the function granularity and refine the granularity of redundant code detection.Firstly,at the module level,JavaScript files are grouped according to the dependency relationship between modules,and the dependency path of each file is analyzed to prevent the repeated calculation of public dependencies.Secondly,at the function level,we collect the function information,analyze the call relationship,and identify and report the redundant function calls in the static structure.Comparative experiments show that the static analysis structure can effectively identify the function call edge and improve the detection accuracy.(2)A hybrid analysis strategy based on static analysis and dynamic execution is proposed to improve the accuracy of identifying redundant functions.Firstly,Jalangi is used for dynamic instrumentation,and the passive measurement technology is used to obtain the usage of JavaScript resources in the actual loading of the application.The runtime trajectory of the dynamic characteristics that are difficult to identify by static analysis is collected to ensure the code coverage.Finally,the hybrid function call graph is generated by combining the dynamic and static results,and the function nodes whose root nodes are unreachable in the graph are identified as redundant.(3)Based on the above strategy,a JavaScript code reduction tool is designed and implemented.The tool includes static statistics function,dynamic instrumentation function,redundancy optimization function,and can simplify the function body of the identified redundancy function.The experimental results show that the tool is simple and effective,reducing the amount of code in the deployment package by 28.59%on average,and optimizing the application loading performance on the basis of ensuring code robustness. |