GNU LibreJS 6.0.4: JavaScript Detection

Next: Free Licenses Detection, Previous: How to Use, Up: Top [Contents]

## 5 JavaScript Detection

- LibreJS considers JavaScript on a page as nontrivial if:
- it makes an AJAX request or is loaded along with scripts that make an AJAX request,
- it loads external scripts dynamically or is loaded along with scripts that do,
- it defines functions or methods and either loads an external script (from HTML) or is loaded as one,
- it uses dynamic JavaScript constructs that are difficult to analyze without interpreting the program or is loaded along with scripts that use such constructs. These constructs are:
  - using the eval function,
  - calling methods with the square bracket notation,
  - using any other construct than a string literal with certain methods (`Obj.write`, `Obj.createElement`, ...).

In practice, the JavaScript code in your page may be found trivial by LibreJS if, as a whole:

- it does not defines functions and it does not load external scripts (with the HTML src attribute in a `<script>` tag);
- it does not make AJAX calls;
- it does not load external scripts with dynamic constructs;
- it does not use constructs that may be used to do any of the above in a non-obvious way (use of the `eval()` method, use of square bracket method calls, use of concatenation with certain constructs or method calls, ...)

However, in some instances, you may be required by LibreJS to add a stylized comment to JavaScript code that may be otherwise trivial.

When an external file defines a function/method, it becomes available to all other external scripts. That is the case if another script defines a function that makes AJAX calls, when an external script loads other scripts dynamically (which in turn could also make AJAX calls, ...), or when a script is written with constructs that may do any of these.

For instance, if your page contains the following:

    <script src="jquery.js"></script>
    <script>
    $.doSomething();
    </script>

While `$.doSomething();` may seem trivial, you will nevertheless have to add a stylized license comment on your main HTML page because the external script (in this case jQuery) has been found to define methods that make AJAX calls. `$.doSomething()` might make an AJAX call, and LibreJS does not check for that. The rule of thumb is that when you use a library or code that handles AJAX, JSON, JSONP, the loading of scripts dynamically, you should have license mentions for all your JavaScript files and for your main page regardless. In practice this is a case that happens very often with code that uses libraries.

In practice also, the JavaScript code in an external file (an external `.js` file loaded on your page) may be found trivial if it does not define functions/methods.

And in the same manner it will be considered nontrivial if AJAX calls, dynamic script loading, or non-obvious dynamic JavaScript constructs are used in another script.

Next: Free Licenses Detection, Previous: How to Use, Up: Top [Contents]