GNU LibreJS 6.0.4: Setting Your JavaScript Free

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

## 7 Setting Your JavaScript Free

Do you own or maintain a website? If so, you can take a stand for user freedom. All you need to do is to release your JavaScript code under a free license that will be easily identified by users while visiting your pages. If you are already using a free library or made a JavaScript app from scratch, it might only take a few minutes!

All JavaScript code on a page (inline, on-page, and external) shares a common scope, and thus 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, by taking 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 while loading. This can help give you an overview of the JavaScript in your page.

- Imagine a page that would contain several pieces of JavaScript from various sources:
- On top, within the `<head>` tag, it may have a link to a jQuery library file,
- under, some JavaScript code that you have written,
- at the bottom a JavaScript-based Facebook widget,
- and an Analytics tracker.

- 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 may not need to look further. But if no mention of the license is made or if it is too brief, you may have to look for a COPYING or LICENSE file within the original library source package or on the official website of the library.
- 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 More likely than not, some of the JavaScript on your page will be nonfree. 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 in order 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 are using a third-party service such as an Analytics service, replace it with a free alternative such as Piwik.
  - And if you really cannot 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 Adding a stylized comment in your JavaScript files and on your page

Once you have identified all JavaScript and replaced or removed the nonfree ones, you can start adding explicit license notices in your JavaScript files and on your pages. Starting from the external files is probably easier. You can use long license notices.

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 no nonfree code was carelessly appended at the end of the file.

For the main HTML page, what the license notice will cover is the JavaScript contained in all `<script>` 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.

### 7.2 JavaScript Web Labels

You can also choose to publish license information about your external JavaScript files using the JavaScript Web Labels method. Extensive information on JavaScript Web Label is detailed at the following URL: http://www.gnu.org/licenses/javascript-labels.html

The JavaScript Web Labels allow you to easily provide –in the same time– information for LibreJS and for your users. All it requires is to create a page listing JavaScript files and the canonical urls of their free licenses.

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