开发者

Find all javascript files not in use

开发者 https://www.devze.com 2023-03-08 09:47 出处:网络
I\'ve inherited an legacy project with tons of javascript files a开发者_Go百科ll over the place...

I've inherited an legacy project with tons of javascript files a开发者_Go百科ll over the place... Is there a way to find which of those files are used inside pages?

Thanks in advance.


Use a debugging tool like YSlow! http://developer.yahoo.com/yslow/

Such tools will usually point out redundant files and code.


  1. You can inspect the website logs of past, say, one month, and locate all *.js files requested by browsers. The log might contain referrer page which makes things easier.

  2. Something that I do very often for .asp files: find a good text editor that allows you to find text inside files/folders. Visual Studio .NET does an excellent job but I've tried and had success with Notepad++ too. Find all files that contain .js. If your text editor provides regular expressions support for searching (the aforementioned products do) this makes things even better. The regexp I use in VS is \.asp> (dot asp followed by a word boundary). The search results are often displayed in a window from where you can copy every thing and do some manual processing via more regex operations or copy the data to an excel file.

  3. Macromedia Dreamweaver does an acceptable job if your website has some structure in it. There is a "Find broken links" command in Dreamweaver that generates a side report called "Orphaned files". The orphaned files report can tell you which js files are not referenced by any page. Then you can run the Dreamweaver's "Find" command (find in entire local website/find in folder) to double check each file one by one. I've tried that too. One thing to note is that Dreamweaver might not be able to detect cycles. E.g. if a file foo.js is used by bar.asp but bar.asp itself is not referenced by any other page, Dreamweaver will flag bar.asp as orphan but not foo.js. The recent version of Dreamweaver might do a better job.


You could create a script in a general purpose scripting language that runs through every html file in your project, checking their script tags. Or you could just do it manually, which may or may not save you some time depending on the size of your project.

0

精彩评论

暂无评论...
验证码 换一张
取 消