Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if certain javascript code is actually used?

Tags:

I am doing some JavaScript cleanup work on a legacy project, and trying to get rid of redundant JS libraries. I have done all the obvious ones (those that are not references from anywhere at all). But there are a number of JS files that are included in all pages (via tiles).

How can I find out whether they are actually used, short of going through content of each and search for each function in them? Is there a smarter/easier way to do this? It's a java based / Spring project if that helps by the way.

like image 463
Ashkan Aryan Avatar asked May 31 '13 09:05

Ashkan Aryan


People also ask

How can I tell which JavaScript page is being used?

Open up the page in chrome, right click on the page and select inspect element (or press ctrl+shift+I). From there you can navigate the different elements on the the page and the structure of the HTML file.

Can you inspect JavaScript?

Chrome. Open Chrome and navigate to the web page containing the JavaScript you want to view. Right-click an empty area on the web page and select Inspect in the pop-up menu to open the Chrome developer tools.

How can I tell if a JavaScript file is requested by a page?

A simple way to see what files are downloaded is to hit F12 in Internet Explorer to open up the Developer Tools. Then go to the Network tab, refresh the page and you'll see the requests made.


1 Answers

One of the latest updates from the chrome dev tools now includes a JS and CSS coverage tab that allows you to see your unused code.

https://developers.google.com/web/updates/2017/04/devtools-release-notes

1) Open the Command Menu. 2) Start typing Coverage and select Show Coverage. 
like image 52
li x Avatar answered Sep 21 '22 06:09

li x