I've inherited a page that is extremely complex and has a ton of <script src=...
includes.
I suspect a lot of the includes are not used. Is there a way to figure out which of them are not used?
Yes there is a way to look at all of a webpages html, Javascript files, and CSS using Chrome. 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.
Yes, JavaScript can be used without html. Node is another option. JavaScript was originally a web scripting language until node js was introduced.
Including the JavaScript You can include JavaScript in your HTML in two ways: Writing the code in your HTML. Including it as a link to an external file.
The in operator returns true if the specified property is in the specified object or its prototype chain.
Chrome 59 includes a new Coverage tool, which can be enabled from the 3-dot menu in DevTools.
You should be able to enable the tool, navigate the website and perform scripted actions, and then view which lines were actually called. Files that are not called will appear entirely red (no lines run).
Edit: As mentioned in the comments, this is still not an optimal solution, since it will only detect lines which have actually run. As @adeneo mentioned, it is almost impossible to statically determine which parts of the code will run, simply because of the complexity of JS.
If this is an XY Problem actually intended to decrease the number of initial HTTP requests, it may be a good idea to simply concatenate all required files and minify that (HTTP/1.1), or investigate grouping related assets and serving via HTTP/2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With