GNU LibreJS 6.0.6: Setting Your JavaScript Free

Next: Installation Requirements, Previous: Free Licenses Detection, Up: Top [Contents]

## 7 Setting Your JavaScript Free

The first step is releasing your JavaScript under a free license. If you are already using a free library, or you’re not using any third-party libraries, it might only take a few minutes.

All JavaScript code on a web page (inline, on-page, and external) shares a common scope. Thus, code is generally either rejected or accepted as a whole by LibreJS. If some JavaScript code is found to be nontrivial and nonfree, then most of the time, all the the rest is discarded as well.

On your website, take a look at your HTML source. You can identify distinct pieces of JavaScript that might be free and some other that are nonfree.

Tip: By running LibreJS on your page, you will get a list of all the JavaScript that was blocked. This gives you an overview of the JavaScript in your page.

Imagine a page that contains several pieces of JavaScript from various sources:

- On top, within the `<head>` tag, it includes jQuery
- Then, some JavaScript code that you have written
- At the bottom, a JavaScript-based Facebook widget
- Also, there’s some analytics tracking code

JavaScript that is already free

  First, you must ensure that the library is free. If the file contains a copyright and a license notice, you won’t need to look any further. But if there’s no mention of the license, or if it’s too brief, you’ll have to look for a COPYING or LICENSE file within the original library’s source package, or on the library’s official website.

Your own JavaScript

  The free license given to your code should be compatible with the rest of the JavaScript on a page. A good way to check is to read up on them: http://www.gnu.org/licenses/license-list.html

Nonfree JavaScript

  This might be the case with an analytics tracker, social media widgets, and code that runs ads. Removing these pieces of code from your site is required to have the rest accepted as free. There are often alternatives to nonfree libraries or to third-party services:

  - If you have used nonfree third-party code as the base to write your own code, try to find a free alternative.
  - If you’re using a third-party service such as an analytics service, replace it with a free alternative like Piwik.
  - If you can’t find free JavaScript that has already been developed, write it yourself! Who knows, your own solution might be the start of a brilliant project!

### 7.1 JavaScript Web Labels

One way to make your website work with LibreJS is by defining a JavaScript Web Labels table.

A JavaScript Web Labels table is informative to both site visitors and the LibreJS program. You make a Web Labels table on a new HTML page that’s linked to from your main page. The table lists each of your site’s JavaScript files, that file’s corresponding human-readable source file, and the canonical url of its free license.

More information on JavaScript Web Labels is detailed here: http://www.gnu.org/licenses/javascript-labels.html and here: https://www.gnu.org/software/librejs/free-your-javascript.html#step3.

### 7.2 Adding a stylized comment in your JavaScript files and on your page

See a “Convention for releasing free JavaScript programs” in the JavaScript Trap http://www.gnu.org/philosophy/javascript-trap.html

Adding this notice will ensure LibreJS will find the JavaScript file to be free. The `@licstart` and `@licend` lines at the beginning and end of the stylized comment are necessary to make a clear statement that the _entire code_ in the file is free. This means that you must ensure that no nonfree code was carelessly appended at the end of the file.

In the main HTML page, the license notice covers JavaScript contained in all `<script>` tags with on-page code and the inline JavaScript (in event attributes such as onload, onclick, etc, …). Since external files have their own stylized comment, they are not covered by the notice in the main HTML page. Make sure to identify all the licenses available. LibreJS will only ensure it matches a notice of an allowed license once, so the order does not matter, but the responsibility is on you to make sure all code is under the free licenses mentioned between `@licstart` and `@licend`.

You should make only one `@licstart` `@licend` comment in your page, since it pertains to the entire code on page across all `<script>` tags and inline html attributes.

For more info on making your JavaScript LibreJS-complaint, see this web page: https://www.gnu.org/software/librejs/free-your-javascript.html

Next: Installation Requirements, Previous: Free Licenses Detection, Up: Top [Contents]