jQuery UI - find unused functions

Hello,

I am currently working on a site that has been created over the years by a variety of contractors and the number of included javascript files has become huge.

The jquery-ui-1.8.14 file is 190 KB and I would like to clean it up and remove unused functions. Does anyone have suggestions for a way to find them? I could delete them one by one and see if it breaks anything, but the site is quite large and I am not sure where all the pages using jQuery UI are…

Thanks in advance.

Mark

Hi,

I’m afraid this might be a little tricky, as in JavaScript you can call functions in some quite dynamic ways.

E.g. imagine you have this:

function  populate_Fields(arg1, arg2){  ... }

It would be possible to invoke the function like this:

var function_prefix = "populate";
var function_name = "Fields";
window[function_prefix + '_' + function_name ]("arg1", "arg2");

Which makes it very hard to find redundant code.

Saying that though, there are tools like JSCoverage, which generate code coverage statistics showing you which lines of a program have been executed (and which have been missed).
Maybe that’s a good place to start.

You might also find this discussion helpful:
http://stackoverflow.com/questions/4136738/find-dead-javascript-code