JavaScript libraries and CSS frameworks are very popular these days. With each library, plugin, extension and template, comes another licencing statement. For most of these licences (MIT, for instance), you must include the licence statement in order to be able to use the code. In many cases, you also have to provide the original source and your own modifications. While, for uncompiled technologies such as these, this is a trivial matter, both this requirement and that of including the licence are awkward to implement if you like to minify your code. The licence is usually kept in an uncompressed comment at the top of the library (the YUI compressor specifically takes this into account with comments marked /*! */ ) and, although anyone can read your modifications to whatever you've used, post-minification code is much harder to follow (cf. three of my last four blog posts) and is really not 'in the spirit' of sharing your code.
I'd like to be able to bundle all the licences and sources together outside the production files. Somewhere the interested user would be able to look them up if they liked but not somewhere that would automatically be downloaded on a standard visit. To that end, I have looked around for an established standard for this and not found anything. If you know of one, please let me know. Until I do find a good standard, here's my suggestion – a simple XML file located at /licences.xml in the format outlined below. It contains details of the file the licence pertains to, the uncompressed source (optional), the title of the licence and a URL where the full licence text can be found (on opensource.org or creativecommons.org, for instance). It also includes a (probably superfluous) shortname for the licence. I might remove that bit. You can optionally include this meta in your HTML if you want an explicit link between your source and the licence file:
<meta name="licences" value="/licences.xml" />
I'm currently undecided as to whether to go with XML or JSON. They're fairly interchangeable (barring XML attributes) but JSON takes less space. Then again, there's not as much need to save space in this file. Anyone have any recommendations? The entire format is, of course, up for discussion. Have I forgotten anything? Have I included anything unnecessary? I'm going to start using this in my projects until someone points out some major legal problem with it, I think.
XML
<licences> <licence> <source> <url> /includes/script/jquery/1.4/jquery.min.js </url> <uncompressed> /includes/script/jquery/1.4/jquery.js </uncompressed> </source> <deed> <title> MIT License </title> <url> http://www.opensource.org/licenses/mit-license.php </url> <shortform> MIT </shortform> </deed> </licence> <licence> <source> <url> /includes/script/custom/0.1/custom.js </url> <uncompressed> /includes/script/custom/0.1/custom.min.js </uncompressed> </source> <deed> <title> Attribution Share Alike </title> <url> http://creativecommons.org/licenses/by-sa/3.0 </url> <shortform> cc by-sa </shortform> </deed> </licence> </licences>
JSON
{ licences:{ { source:{ url:'/includes/script/jquery/1.4/jquery.min.js', uncompressed:'/includes/script/jquery/1.4/jquery.js' }, deed:{ title:'MIT License', url:'http://www.opensource.org/licenses/mit-license.php', shortform:'MIT' } }, { source:{ url:'/includes/script/custom/0.1/custom.min.js', uncompressed:'/includes/script/custom/0.1/custom.js' }, deed:{ title:'Attribution Share Alike', url:'http://creativecommons.org/licenses/by-sa/3.0', shortform:'cc by-sa' } } } }