find dead JavaScript code?

后端 未结 8 893
醉酒成梦
醉酒成梦 2020-12-05 05:51

We are refactoring a legacy web app and as a result are \"killing\" quite a lot of JavaScript code but we\'re afraid of deleting what we think is dead code due to not being

8条回答
  •  自闭症患者
    2020-12-05 06:51

    You could use code optimizers as Google Closure Compiler, however it's often used for minimizing code.

    function hello(name) {
    alert('Hello, ' + name);
    }
    
    function test(){
    alert('hi');
    }
    
    hello('New user');
    

    Will result in

    alert("Hello, New user");
    

    For example.

    Another thing you could do is to use Chrome's Developer Tools (or Firebug) to see all function calls. Under Profiles you can see which functions are being called over time and which are not.

    DT Profiles

提交回复
热议问题