Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of all JS files loaded on a web page

Tags:

javascript

A bit of a newbie question but what is the best way to get a list with full name path of all JS files loaded on my website?

To clarify: I have a page www.mypage.com - I want to get a list of all the JS files with their full name paths which are loaded on this page.

like image 968
JoaMika Avatar asked Aug 25 '16 11:08

JoaMika


2 Answers

You can also use the Performance API:

var entries = performance.getEntriesByType('resource');
entries.map(function(entry) {
  if (entry.initiatorType === 'script') {
    console.log('JS file:', entry.name);
  }
});
like image 117
Armel Avatar answered Oct 20 '22 22:10

Armel


You should get all the script tags first::

var scripts = document.getElementsByTagName('script');

And then loop through it:

for(var i=0;i<scripts.length;i++){
scripts[i].src;
}
like image 26
Ruhul Avatar answered Oct 20 '22 23:10

Ruhul