Is there a tool to remove unused methods in javascript?

前端 未结 7 1950
一生所求
一生所求 2020-12-02 19:50

I\'ve got a collection of javascript files from a 3rd party, and I\'d like to remove all the unused methods to get size down to a more reasonable level.

Does anyone

7条回答
  •  广开言路
    2020-12-02 20:29

    Unless the library author kept track of dependencies and provided a way to download the minimal code [e.g. MooTools Core download], it will be hard to to identify 'unused' functions.

    The problem is that JS is a dynamic language and there are several ways to call a function.

    E.g. you may have a method like

    function test() 
    {
       //
    }
    

    You can call it like

       test();
    
       var i = 10;
       var hello = i > 1 ? 'test' : 'xyz';
    
       window[hello]();
    

提交回复
热议问题