Reputation: 43
Is there a way to identify if the javascripts included in the website are libraries ?
I mean, the websites generally load several javascript files using tag... I want to know if the file which is being loaded is library (like jquery) or if it is a normal javascript.
Is there a way to find this?
Thanks in advance, Irfan
Upvotes: 0
Views: 269
Reputation: 150040
Javascript libraries are normal Javascript files.
If you want to tell which included files are libraries you can inspect them yourself and reach your own conclusion.
If you want to determine which are libraries programmatically, you can't do this. I mean, what constitutes a library? If I have a JS file with two functions in it is it a library?
You probably could write a function to identify some of the popular libraries based on their standard file names, though obviously that wouldn't catch all cases even of those libraries since there's nothing stopping individual programmers from renaming the files when they use them.
Also for the well-known libraries if your program can read the contents of the include file you could look for some string that you know is included in a particular library. Again far from foolproof.
Or you can put some code after the external scripts are included, to test whether certain global variables are defined, e.g., if there's a jQuery
global then you could reasonably assume that jQuery has been included...
Upvotes: 0
Reputation: 11689
There isn't any difference between a javascript file and a "library", they are just normal javascript files. You can't differentiate them.
Infact your logical way to identify libraries is from well known names and not from a specific parameter.
If you want you can implement a method that looks for well known names, but someone can also rename their javascript files to make them look like libraries for your script.
There is another important note: in rails (for example), all javascript files can be merged into a single one to preserve bandwith usage (they are uglyfied), so maybe you will have name like "v9834kc90l2d0vk34r5lcve.js" which also contains a library. I don't think you can identify it easily.
Why are you doing this by the way?
Upvotes: 2
Reputation: 11637
you can parse the file, a jquery file will start with
/*! jQuery v?.?.? jquery.com | jquery.org/license */
or
/*!
* jQuery JavaScript Library v?.?.?
* http://jquery.com/
other libraries have similar headers.
but this isnt a 100% solution since the header can be deleted manualy.
Upvotes: 1