Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a tool to remove unused methods in javascript?

Tags:

javascript

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 know of a tool that does this for Javascript? At the very least give a list of unused/used methods, so I could do the manually trimming? This would be in addition to running something like the YUI Javascript compressor tool...

Otherwise my thought is to write a perl script to attempt to help me do this.

like image 345
Alan Avatar asked Jul 22 '09 19:07

Alan


People also ask

How do I reduce unused JavaScript?

If your website is running on WordPress, you can remove the unused JavaScript from its pages using special plugins. For example, you can use AssetCleanUp, which also allows you to disable unused JavaScript files. Another option is to detect unused JS with Chrome DevTools and delete unnecessary files.

What does remove unused JavaScript mean?

Overview. Reducing unused JavaScript can reduce render-blocking behaviour to speed up your page load and improve your visitors' page experience. By default, JavaScript files are render-blocking because they block the browser from dealing with other page load tasks, thus delaying your page's First Paint.


2 Answers

No. Because you can "use" methods in insanely dynamic ways like this.

obj[prompt("Gimme a method name.")](); 
like image 169
Kenan Banks Avatar answered Sep 17 '22 20:09

Kenan Banks


Check out JSCoverage . Generates code coverage statistics that show which lines of a program have been executed (and which have been missed).

like image 30
foson Avatar answered Sep 21 '22 20:09

foson