How to remove dead code from Javascript [duplicate]
Asked Answered
J

2

21

I am trying to remove unused functions from my project. Since it has thousands of lines, this takes forever.

Code coverage tools may suggest functions that are not used in a given test case, but it may be dangerous to rely only on this.

Is there another tool which can help with this?

Jordonjorey answered 18/7, 2011 at 8:31 Comment(1)
I fear that tools are your best option - just use more than one tool and rely on their combined output. Save backup of everything and perform full test of everything before going live.Chitterlings
V
13

You can try Google Closure compiler. It has different settings and you can also remove dead code automatically. You can try it here: http://closure-compiler.appspot.com/home

For more info read here: http://code.google.com/closure/compiler/docs/compilation_levels.html

Voguish answered 18/7, 2011 at 8:43 Comment(1)
The "advanced" optimization setting removes dead code automatically.Anthotaxy
G
1

Have a look at this question regarding Javascript static analysis tools.

Gleanings answered 18/7, 2011 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.