1

My JavaScript code is very large even after compression. How can I find all unused functions so I can remove them?

For example in CSS files to remove unused classes I can use the "Dust-Me" Firefox addon. Is there a way to do the same for JavaScript?

Boann
  • 48,794
  • 16
  • 117
  • 146

1 Answers1

-1

I'm not sure if you are referring to Java or Javascript, but my wild guess is it must be Javascript since you mention things like JQuery and CSS. So please fix your title and question description if it is wrong.

Anyway, if you are looking for a way to list down all javascript functions, please take a look at this: How to list all of javascript functions beginning with _func

You can just ignore the 'func' filtering.
e.g.
if(typeof window[x] === "function") functions.push(x);

Although we still need to find a way to filter it.

Another way is to just have an array that will mark if a function is being called.
e.g.

usedFunctions = array();
function myFunc(){    
    usedFunctions.push('myFunc');
}
Community
  • 1
  • 1
Alvin Tandian
  • 171
  • 1
  • 9