Next: , Previous: , 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:

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:

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:

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.

When using a JavaScript Web Labels table for your own files, it’s important to put a copying permission statement at the top of each source file listed in right-most column of the Web Labels table. For info on how properly release your code as free software, see Future versions of LibreJS will require a copying permission statement or other license notice for source files listed in a Web Labels table.

More information on JavaScript Web Labels is detailed here: and here:

7.1.1 Specifying multiple licenses for a single JavaScript file

If you compile or concatenate your JavaScript into a single file, the source files you’re combining may be released under different licenses. You can specify multiple licenses for the file in a JavaScript Web Labels table, like this:

<table id="jslicense-labels1">
        <td><a href="all.min.js">all.min.js</a></td>
            <a href=""
            <br />
            <a href=""
            <a href="gpl-script.js">gpl-script.js</a>
            <br />
            <a href="apache-script.js">apache-script.js</a>

The <br /> tags just make the table more understandable when looking at the rendered version of it on the license page. They aren’t required by LibreJS.

If all the licenses contained in the second column are recognized by LibreJS to be free licenses, then LibreJS will allow the file in the first column to be run.

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

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.

When you use the JavaScript Web Labels method, you should still include a license notice at the top of each of your source files. This ensures that if someone copies the file and uses it for something else, the license remains intact.

For more info on making your JavaScript LibreJS-compliant, see this web page:

Next: , Previous: , Up: Top   [Contents]